In the source code below I am able to change my checkmark
object value, but at the time of reload data in cellForRowAtIndexPath
method it shows old data:
//TableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [self.tableData count];
}
//CellforRowAtIndexpath showing old table data
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Recipe *obj = nil;
obj = self.tableData[indexPath.row];
cell.textLabel.text = obj.name;
NSLog(@"Reload Data %@", obj.checkmark);
if ([obj.checkmark integerValue] == 1)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Recipe *recipe = nil;
recipe = [self.tableData objectAtIndex:indexPath.row];
if ([recipe.checkmark integerValue] == 1)
{
recipe.checkmark=@"0";
}
else
{
//recipe.checkmark=@"1";
for (int i=0; i<[self.tableData count]; i++) {
if (i==indexPath.row) {
recipe.checkmark=@"1";
}
else{
recipe.checkmark=@"0";
}
NSLog(@"PK ! %@", recipe.checkmark);
}
}
//[self.tableData addObject:recipe.checkmark];
[self.myTable reloadData];
[self.myTable reloadData];
}