2017-01-09 19 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 с глобальным значением для этого класса. – 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

В ваш метод действий вы можете найти свой текстовый фильтр, как показано ниже: Вы можете найти IndexPath от SuperView. См. Ниже Код.

UIView *superView = btn.superview; 

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

CustomCell *cell = (CustomCell *)superView; 

вы получите UITextField объект из cell.yourTextFeld. И вы можете использовать TextField согласно вашему требованию.