Reputation: 303
Friend I've been trying to set default Checkmark in my UITableView Cell,Here is my code please look at this, I'm having serious trouble to get my desire output
-(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;
}
I want to get following output From my ResultInfo is , Cell should remember accessory type
Friends I'm having trouble with preCheckmark(Cell Accessory) from My JSON Objects Note I'm getting that Output from Web in JSON Format Any Help will be appreciated ..Thanks
UPDATE When I run this code Getting Exception Like Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-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:'**
Upvotes: 2
Views: 144
Reputation: 3447
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:'*
I guest this exception happen at this line of code
cell = [[self ShapeSelectionTable] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
You should put some break point here and simulate what is happening.
Upvotes: 3
Reputation: 7938
You shouldn't call -selectRowAtIndexPath:animated:
in -cellForRowAtIndexPath:
, you don't have to select a row to show a check mark.
Upvotes: 1