2015年7月11日UITableView3

来源:互联网 发布:ubuntu jdk安装 编辑:程序博客网 时间:2024/05/01 11:51


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];

}






0 0
原创粉丝点击