UITableView的数据刷新,用代码来描述
来源:互联网 发布:编程猫加盟 编辑:程序博客网 时间:2024/05/04 01:32
UITableView通过代理来监听某行被选中的事件。
点击某行, 弹出对话框, 然后修改数据, 再把数据刷新到UITableView上。
1> 监听每个cell的点击事件- 通过代理来监听,
* 选中某行: - (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
* 取消选中某行: - (void)tableView:(UITableView )tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
2> 弹出UIAlertView、UIAlertController
* 修来弹出对话框的样式
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
根据索引获取指定的某个文本框
[alertView textFieldAtIndex:0]
[alertView textFieldAtIndex:0].text = hero.name;通过UIAlertView的代理来监听对话框中的按钮的点击事件
- 实现UIAlertView的 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex代理方法
3> 刷新tableView的方法(刷洗tableView的意思就是重新调用数据源方法和代理方法)
// [self.tableView reloadData]; // 不好,因为重新刷新整个TableView
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
/** 参考代码:
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath
{
CZHero *hero = self.heros[indexPath.row];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alertView.alertViewStyle = UIAlertViewStylePlainTextInput; [alertView textFieldAtIndex:0].text = hero.name; // 记录当前点击的行的行号 alertView.tag = indexPath.row; [alertView show];
}
#pragma mark - alertView的代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// 判断点击的是哪个按钮
if (buttonIndex == 1) {
//获取文本框中的数据 NSString *name = [alertView textFieldAtIndex:0].text; // 修改模型数据 // 根据行号, 获取当前点击的行的模型数据 CZHero *hero = self.heros[alertView.tag]; hero.name = name; // 重新刷新TableView数据 // 重新刷新整个TableView, UITableView会重新向datasource请求数据 // 重新调用数据源方法 // [self.tableView reloadData]; // 不好重新刷新整个TableView // 局部刷新 // 创建一个indexPath对象 NSIndexPath *path = [NSIndexPath indexPathForRow:alertView.tag inSection:0]; [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationLeft]; }
}
*/
- UITableView的数据刷新,用代码来描述
- 设置UITableView刷新某一行的代码
- UITableView刷新单行数据的方法
- UITableView刷新单行数据的方法
- [IOS]UITableView刷新一个分组的数据
- 10.UITableView的刷新数据方法
- UITableView刷新数据reLoadData
- UITableView刷新数据
- UITableView + UIAlertView + 数据刷新
- UITableView数据刷新
- uitableview 数据刷新
- iOS UITableView数据刷新
- UI021---UITableView数据刷新
- UITableView刷新数据reLoadData
- UITableView刷新数据reLoadData
- UITableView表格数据刷新
- iphone开发 UITableView数据刷新
- uitableview上提刷新数据
- MPLS技术学习总结
- C++之静态成员变量、静态成员函数、编译规则、双向依赖
- Shell脚本调试
- linux软链接硬链接复制的区别
- 关于TableView你不知道的哪些事
- UITableView的数据刷新,用代码来描述
- .fvwm2rc
- laravel 指定 版本安装
- LinkedHashMap实现原理
- leetcode (18) - 4Sum
- js基础语法
- AspectJ切入点语法详解
- 1055. The World's Richest (25)
- Android实验五之把数据存到SD卡