OGeek|极客世界-中国程序员成长平台

标题: ios - 在相应的表格单元文本字段更改时更新表格 View 单元的 subview [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:50
标题: ios - 在相应的表格单元文本字段更改时更新表格 View 单元的 subview

我有一个 UITableView,每个 UITableViewCell 都有一个文本字段和 UILabel。当相应单元格中的文本字段已被编辑时,如何更新单元格上的标签字符串。

我尝试了类似的方法,但它不起作用

UITextField *myTextField = (UITextField *)[cell viewWithTag:100];
UILabel *myLabel = (UILabel *)[cell viewWithTag:101];
[myTextField addTarget:self actionselector(textFieldEdited:event forControlEvents:UIControlEventEditingDidEnd];    

- (void)textFieldEditedUITextField*)textfield eventUIEvent*)event
{
    NSIndexPath* indexPath = [myTable indexPathForRowAtPoint:
                          [[[event touchesForView:textfield] anyObject]
                           locationInView:cartTable]];
    NSLog(@"%d",indexPath.row);
    UILabel *myLabel = (UILabel *)[[myTable cellForRowAtIndexPath:indexPath] viewWithTag:101];
    [myLabel setText"44"];
}

但是没有用。



Best Answer-推荐答案


试试这个..这可能对你有帮助。

- (BOOL)textFieldUITextField *)textField shouldChangeCharactersInRangeNSRange)range replacementStringNSString *)string
{
    UITableviewCell *currentCell = (UITableviewCell *) [textField superView];
    UILabel *label = [currentCell viewWithTag:YOURLABELTAG];
    label.text = [NSString stringWithFormat"%@%@",textField.text,string];
    return YES;
}

注意:不要忘记设置textFieldDelegate和设置label Tag

关于ios - 在相应的表格单元文本字段更改时更新表格 View 单元的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20901108/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4