您的位置:首页 > 产品设计 > UI/UE

03-02-UITableView数据刷新

2016-02-15 20:32 459 查看
##效果



##实现
###关键代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// 1.取出被点击行对应的模型
YSHero *hero = self.heros[indexPath.row];
// 打印
//    NSLog(@"%@",hero.name);
// 弹窗,选择类型
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据展示" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *defult = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

UITextField *nameField = alert.textFields.firstObject;
NSString *name = nameField.text;
if ([name isEqualToString:hero.name]) {
return ;
}

// 修改模型数据
hero.name = name;

// 局部刷新
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft ];
//        NSLog(@"name - %@ : %d",nameField.text,indexPath.row);
}];
[alert addAction:cancel];
[alert addAction:defult];

// 添加输入框
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.text = hero.name;
}];

// 显示对话框
[self presentViewController:alert animated:YES completion:nil];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios ui