Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is what I find to work best:</p> <p>(just any code between "Add this" and "End Add this")</p> <p>Also, make sure you change "(Your Number ofRows)" to an object that either returns an int, or is an int itself. Such as myCustomArray.count, or 24.</p> <pre><code>//In .h file add this NSMutableArray *indexArray; //in .m file - (void)viewDidLoad { //Add this indexArray = [[NSMutableArray alloc] init]; int i; for (i = 0; i &lt;= (Your Number ofRows); i++) { [indexArray addObject:[NSNumber numberWithDouble:0]]; } NSLog(@"indexArray = %@",indexArray);//You can check the console now to see if you have an array of "zeros" //End Add this } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; UITableViewCell *curCell = [beerTable cellForRowAtIndexPath:indexPath]; if (curCell.accessoryType == UITableViewCellAccessoryCheckmark) { [curCell setAccessoryType:UITableViewCellAccessoryNone]; compareCount = (compareCount - 1); //Add this [indexArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithDouble:0]]; //End Add this if (tableView == [[self searchDisplayController] searchResultsTableView]) { NSString *objBeer = [searchResults objectAtIndex:indexPath.row]; [compareBeers removeObject:[searchResults objectAtIndex:indexPath.row]]; [compareCarbs removeObject:[carbAmount objectAtIndex:[beerNames indexOfObject:objBeer]]]; } else { [compareBeers removeObject:[beerNames objectAtIndex:indexPath.row]]; [compareCarbs removeObject:[carbAmount objectAtIndex:indexPath.row]]; } } else { [curCell setAccessoryType:UITableViewCellAccessoryCheckmark]; compareCount = (compareCount + 1); //Add this [indexArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithDouble:1]]; //End Add this if (tableView == [[self searchDisplayController] searchResultsTableView]) { NSString *objBeer = [searchResults objectAtIndex:indexPath.row]; [compareBeers addObject:[searchResults objectAtIndex:indexPath.row]]; [compareCarbs addObject:[carbAmount objectAtIndex:[beerNames indexOfObject:objBeer]]]; } else { [compareBeers addObject:[beerNames objectAtIndex:indexPath.row]]; [compareCarbs addObject:[carbAmount objectAtIndex:indexPath.row]]; } } if (compareCount &gt; 0) { if (compareOn == YES){ } else { compareButton.enabled = YES; UIImage *image = [UIImage imageNamed:@"redbutton.png"]; [compareButton setImage:image]; } } else { compareButton.enabled = NO; [compareButton setImage:nil]; [compareButton setCustomView:nil]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; for (id currentObject in topLevelObjects){ if ([currentObject isKindOfClass:[UITableViewCell class]]){ cell = (CustomCell *) currentObject; break; } } } // Setting separate tables correctly.... //Add this if ([[indexArray objectAtIndex:indexPath.row] doubleValue] == 1) { cell.accesoryType = UITableViewCellAccesoryTypeCheckmark; } else { cell.accesoryType = UITableViewCellAccesoryTypeNone; } //End Add this return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload