2017-01-09 13 views
-1
-(void)sendcomment:(UIButton *)sender{ 

    NSLog(@" send commment server"); 

    thirdviewcellTableViewCell *dja =[[thirdviewcellTableViewCell alloc] init]; 
    NSString *vga = [[NSString alloc] init]; 
    vga=dja.celltext; 
    NSLog(@"comment value is %@",vga); 
    NSLog(@"comment cell value is %@",dja.celltext); 
} 
+0

このメソッドでは、ローカルのtextFieldを作成し、そのテキストを取得しようとしています。しかしそれは空であるべきです。そのクラスのグローバル値でtextFieldを保持する必要があります。 – alicanbatur

答えて

1
-(void)sendcomment:(UIButton *)sender 
{ 
UIButton *button = (UIButton*)sender; 
NSIndexPath *indexpath = [NSIndexPath indexPathForRow:sender.tag inSection:0]; 
UITableViewCell *cell = (UITableViewCell*)[tblView cellForRowAtIndexPath: indexpath]; 
    // If you have text field 
UITextField *textfiled = (UITextField *)[cell.contentView viewWithTag:yourtextfeildtagvlaue]; 

// NSString *vga = textfiled.text 
} 
0

電池はボタンを押した場合は、あなたがこれを行うことができます:

-(void)sendcomment:(UIButton *)sender{ 

    // 1. get the position the button you clicked 
    CGPoint correctedPoint = [sender convertPoint:button.bounds.origin toView:self.tableView]; 

    // 2. find the cell via the position 
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:correctedPoint]; 
    thirdviewcellTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];; 

    // 3. then you can get the TextField value 
    NSString *textFieldValue = [[NSString alloc] init]; 
    textFieldValue = cell.celltext; 
} 
0

あなたがで

-(void)sendcomment:(UIButton *)sender 
    { 
    UIButton *button = (UIButton*)sender; 
    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:sender.tag inSection:0]; 
    UITableViewCell *cell = (UITableViewCell*)sender.superview.superview;// get cell using view hierarchy 
     // If you have text field 
    UITextField *textfiled = (UITextField *)[cell.contentView viewWithTag:yourtextfeildtagvlaue]; 
    // NSString *vga = textfiled.text 
    } 

* 
0

セルの階層を使用してセルを取得あなたのアクションメソッドはあなたのTextFieldを以下のように見つけることができます: SuperPathからIndexPathを見つけることができます。 コードを参照してください。

UIView *superView = btn.superview; 

while (![superView isKindOfClass:[UITableViewCell class]]) { 
    superView = superView.superview; 
} 

CustomCell *cell = (CustomCell *)superView; 

あなたはcell.yourTextFeldからUITextFieldオブジェクトを取得します。 あなたの要件に合わせてTextFieldを使用することができます。

関連する問題