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

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: