UITableView调用的方法
2013-05-08 17:40
113 查看
UITableView实现两个协议UITableViewDataSource和UITableViewDelegate
#pragma mark 一共有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
#pragma mark 每一行显示什么数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
#pragma mark 设置某一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{}
#pragma mark 点击了某一行的cell就会触发这个方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndex:(NSIndexPath *)indexPath{}
//提交编辑操作时会调用这个方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{}
//取出选中这一行
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//取得对应位置的Cell对象
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//让Cell打钩
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//将分割线去掉
tableView.separatorColor = [UIColor clearColor];
//判断原来的Cell在不在集合里面,如果在就check,否则不check
NSString *text = [self.data ObjectAtIndex:indexPath.row];
if ([self.selectedData containsObject:text]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableVIewCellAccessoryNone;
}
//循环利用的Cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if(cell == nil){
//如果没有可循环利用的Cell,就必须创建一个Cell
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"UITableVIewCell"] autorelease];
}
//重新向dataSrouce请求数据
//重新调用数据源的方法numberOfRowsInSection和cellForRowAtIndexPath
[tableview reloadData];
//更新UI并有动画效果
[self.tableView deleteRowsAtIndexPaths:self.selectedRows
withRowAnimation:UITableViewRowAnimationAutomatic];
//清除数组中的数据
[removeAllObjects];
#pragma mark 一共有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
#pragma mark 每一行显示什么数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
#pragma mark 设置某一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{}
#pragma mark 点击了某一行的cell就会触发这个方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndex:(NSIndexPath *)indexPath{}
//提交编辑操作时会调用这个方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{}
//取出选中这一行
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//取得对应位置的Cell对象
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//让Cell打钩
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//将分割线去掉
tableView.separatorColor = [UIColor clearColor];
//判断原来的Cell在不在集合里面,如果在就check,否则不check
NSString *text = [self.data ObjectAtIndex:indexPath.row];
if ([self.selectedData containsObject:text]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableVIewCellAccessoryNone;
}
//循环利用的Cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if(cell == nil){
//如果没有可循环利用的Cell,就必须创建一个Cell
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"UITableVIewCell"] autorelease];
}
//重新向dataSrouce请求数据
//重新调用数据源的方法numberOfRowsInSection和cellForRowAtIndexPath
[tableview reloadData];
//更新UI并有动画效果
[self.tableView deleteRowsAtIndexPaths:self.selectedRows
withRowAnimation:UITableViewRowAnimationAutomatic];
//清除数组中的数据
[removeAllObjects];
相关文章推荐
- UITableView的scrollViewDidEndDragging方法执行之后调用cellForRowAtIndexPath方法问题
- UITableView的cellForRowAtIndexPath方法被不必要的调用很多次的问题
- iOS UITableView数据源与代理方法的调用(一)
- 调用、函数-UITableView内容无法刷新的解决方法-by小雨
- 调用删除方法UITableView deleteRowsAtIndexPaths的时候就挂掉
- 调用一个UITableview的一个代理的方法,实现UITableview重载
- UITableView reloadData后,cellForRowAtIndex方法未调用问题
- 调用删除方法UITableView deleteRowsAtIndexPaths的时候就挂掉
- Android使用WebView播放flash的方法和JavaScript调用本地方法
- view类某些控件创建时候系统自动帮助我们调用的某些方法
- UITableView常用方法、属性总结
- iOS8调用相机报警告Snapshotting a view的解决方法
- 防止UITableview被UITabBar遮挡的方法:(ios9验证)
- Swift - UIView,UItableView,Cell设置边框方法
- 详解iOS开发中UITableview cell 顶部空白的多种设置方法
- UITableView中Cell重用机制导致内容重复解决方法
- 解决UITableView中Cell重用机制导致内容出错的方法总结
- UITableView刷新单行数据的方法
- iOS UITableView 默认选择某行的方法
- UITableView中Cell重用机制导致内容重复解决方法