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

2015年7月11日UITableView3

2015-07-12 11:02 281 查看
UITableViewCell  代理事件

通过UITableViewDelegate 

//取消选中
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    //当点击下一个的时候  会同时调用这个和 选中
    
}

数据刷新
1.获得textfiled中的 数据

//选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    Heroes* hero = self.Heros[indexPath.row];
    
    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"数据刷新" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    //1.想添加 textfiled
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    
    //2.取得最后的那个文本
    [alert textFieldAtIndex:0].text = hero.name;
    
    [alert show];
    
    
    alert.tag = indexPath.row;
}

2.通过UIAlertDelegate 来修改 textfiled 中数据

#pragma mark - alert代理方法

//点击上面的按钮就会调用
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    //buttonIndex  按钮的索引  0 1
    
    if(buttonIndex == 0)return;
    
    //1.取得文本框 最后的文字
    NSString* str = [alertView textFieldAtIndex:0].text;
    
    //2.修改模型数据
    int row = alertView .tag;
    
    Heroes* her = self.Heros[row];
    her.name = str;
    
    //3.告诉 TableView 重新加载数据
    //全部刷新
//    [self.tableView reloadData];
    
    //局部刷新
    NSIndexPath* path = [NSIndexPath indexPathForRow:row inSection:0];
    [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios uitableview