我uitableview的(cell=nil)总是不调用?
I uitableview the (cell = nil) always not call?
在 ui table 视图单元格中,
语句 if (cell == nil) 没有被调用。
因为当我在 if 语句之外初始化单元格时,表格将在错误的行中有一些错误的标签。
如何初始化我的手机?
@"tttestttt" NS LOG并不是一直在创建table的时候
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"GroupsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
NSLog(@"tttesttttt");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
}
<a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier:" rel="nofollow">dequeueReusableCellWithIdentifier:</a>
如果您使用 Storyboard,则总是 return 一个单元格。
使用更方便的方法dequeueReusableCellWithIdentifier:forIndexPath:
,returns 始终是有效的单元格。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"GroupsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier
forIndexPath:indexPath];
...
return cell;
}
使标识符不是固定值
将其设为index.row(转换为字符串作为标识)
你的错误可能是电池垃圾箱
在 ui table 视图单元格中, 语句 if (cell == nil) 没有被调用。
因为当我在 if 语句之外初始化单元格时,表格将在错误的行中有一些错误的标签。
如何初始化我的手机?
@"tttestttt" NS LOG并不是一直在创建table的时候
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"GroupsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
NSLog(@"tttesttttt");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
}
<a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier:" rel="nofollow">dequeueReusableCellWithIdentifier:</a>
如果您使用 Storyboard,则总是 return 一个单元格。
使用更方便的方法dequeueReusableCellWithIdentifier:forIndexPath:
,returns 始终是有效的单元格。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"GroupsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier
forIndexPath:indexPath];
...
return cell;
}
使标识符不是固定值
将其设为index.row(转换为字符串作为标识)
你的错误可能是电池垃圾箱