friend ,我一直在尝试在 UITableView 单元格中设置默认复选标记,这是我的代码,请看一下,我在获得所需的输出时遇到了严重的问题
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdent = @"cell1111";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
if (tableView==_ShapeSelectionTable)
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [_ShapeSelectionTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if([_selectedShapeArray containsObject:[_shapeArray objectAtIndex:indexPath.row]] || [_selectedShapeArray containsObject:@"Check All"]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
for (NSString *s in _shaperesultArray)
{
for (int i=0; i<self.shapeArray.count; i++)
{
NSIndexPath *myIdx=[NSIndexPath indexPathForRow:i inSection:0];
ShapeInfo *shap=[self.shapeArray objectAtIndex:i];
if ([shap.shape isEqualToString:s])
{
cell = [[self ShapeSelectionTable] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
cell.accessoryType=UITableViewCellAccessoryCheckmark;
//[tableView selectRowAtIndexPath:myIdx animated:TRUE scrollPosition:UITableViewScrollPositionNone];
}
else
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
}
}
ShapeInfo *shap=[_shapeArray objectAtIndex:indexPath.row];
cell.textLabel.text=shap.shape;
return cell;
}
我想从我的 ResultInfo 获得以下输出,单元格应该记住附件类型
friend 们,我在使用我的 JSON 对象中的 preCheckmark(Cell Accessory) 时遇到问题 注意我从 Web 获取 JSON 格式的输出 任何帮助将不胜感激..谢谢
更新当我运行此代码时出现异常 -[UITableView _configureCellForDisplay:forIndexPath:]、/SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:6509 中断言失败 2014-06-24 14:14:24.306 TheGemHubApp[2405:60b] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView dataSource 必须从 tableView:cellForRowAtIndexPath:'**
返回一个单元格
最佳答案
2935.137/UITableView.m:6509 2014-06-24 14:14:24.306 TheGemHubApp[2405:60b] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'*
我猜这个异常发生在这行代码
cell = [[self ShapeSelectionTable] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
您应该在此处放置一些断点并模拟正在发生的情况。
关于ios - 在 UITableviewCell 中选择行时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24381935/