* 监听到cell点击选中后会调用的方法
*
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// 0.取得点击的cell(第一种方式)
// UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// 1.创建一个弹框
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
// 2.让弹框中出现一般的textFeild
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
// 2.1取得textFeild
UITextField *nameTextFeild = [alert textFieldAtIndex:0];
alert.tag = indexPath.row;
// 2.2把对应的cell中的名称赋值给nameTextFeild
// nameTextFeild.text = cell.textLabel.text;
HeroModel *hero = self.heros[indexPath.row];
nameTextFeild.text = hero.name;
self.tableView.delegate = self;
// 3.弹出
[alert show];
}
/**
* 监听到alertView中按钮的点击调用的方法
*
*/
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
// 1.修改模型
HeroModel *hero = self.heros[alertView.tag];
// 1.1取得文字
hero.name = [alertView textFieldAtIndex:0].text;
// 2.刷新数据
// [self.tableView reloadData];//全局刷新
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:alertView.tag inSection:0];
// 2.1局部刷新
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}