Objective c 复选标记代码错误
在我的Objective c 复选标记代码错误,objective-c,ios,uitableview,uikit,Objective C,Ios,Uitableview,Uikit,在我的cellForRow代码中,我有以下内容,并且收到一个错误,表示没有返回任何内容。我做错了什么?谢谢 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; if([self.check
cellForRow
代码中,我有以下内容,并且收到一个错误,表示没有返回任何内容。我做错了什么?谢谢
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
if([self.checkedIndexPath isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
这是一个无休止的循环:
UITableViewCell*cell=[tableView cellforrowatinexpath:indexath]代码>
这应该是:
static NSString *reuseIdentifier = @"some_identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier] autorelease]
}
这是一个无休止的循环:UITableViewCell*cell=[tableView cellforrowatinexpath:indexath]代码>
这应该是:
static NSString *reuseIdentifier = @"some_identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier] autorelease]
}
您的cellforrowatinexpath
将如下所示(对于最基本的表视图)
您的cellforrowatinexpath
将如下所示(对于最基本的表视图)
您是否尝试使用调试器单步执行函数?是否尝试使用调试器单步执行函数?虽然您对单元格创建的看法是正确的,但这不会创建无限循环。这会将消息-cellforrowatinexpath:
发送到UITableView
的实例。发送它的方法是UITableViewDelegate
上的-tableView:cellforrowatinexpath:
。我添加了这个方法,它仍然做同样的事情。这里是:-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{static NSString*reuseIdentifier=@“Cell”;UITableViewCell*Cell=[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];if(Cell==nil){Cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];}if(indexath.row==0){cell.accessoryType=UITableViewCellAccessoryCheckmark;}if([self.checkedIndexPath isEqual:indexath]){cell.accessoryType=UITableViewCellAccessoryCheckmark;}else{cell.accessoryType=UITableViewCellAccessoryNone;}返回单元格;}仍然无法使用上面的代码加载我的数组,因为它是在我添加复选标记代码之前加载的。虽然您对单元格创建的看法是正确的,但这不会创建无限循环。这会将消息-cellforrowatinexpath:
发送到UITableView
的实例。发送它的方法是-tableView:cellForRowAtIndexPath:
在UITableViewDelegate
上。我添加了它,它仍然做同样的事情。这里是:-(UITableViewCell*)tableView:(UITableView*)tableView单元格FORROWATINDEXPATH:(nsindepath*)indepath{static NSString*reuseIdentifier=@“Cell”;UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];if(cell==nil){cell=[[UITableViewCellAlloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];}if(indexath.row==0){cell.accessoryType=UITableViewCellAccessoryCheckmark;}if([self.checkedIndexPath isEqual:indexPath]){cell.accessoryType=UITableViewCellAccessoryCheckmark;}否则{cell.accessoryType=UITableViewCellAccessoryNone;}返回单元格;}仍然无法使用上面的代码加载我的数组,因为它是在我添加复选标记代码之前加载的。