dequeueReusableCellWithIdentifier: 与dequeueReusableCellWithIdentifier: forIndexPath:的区别

来源:互联网 发布:淘宝君羊令页是真的吗 编辑:程序博客网 时间:2024/04/25 17:41

如果注册了cell

[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"CustomCell"];

则在- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath这个方法里,可以把下边的代码:

 static NSString *CellIdentifier = @"Cell";    if (cell == nil) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];      //设置你的cell

替换成下边的代码:

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
0 0
原创粉丝点击