Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This method is called once for each cell that needs to be filled. If you scroll the table, rows will go off the screen and be queued with their reuse identifier. When rows scroll onto the table, this method is called to fill the cells as they become visible. </p> <p>So first, you only want to dequeue one cell each time this method is called. By dequeuing cells of type <code>UITableViewCell' and</code>UITableViewCellB' you are dequeuing one that isn't going to be used. So you need to determine which type of cell you need before you dequeue one, and then dequeue the right type (by its reuse identifier).</p> <p>Second, the purpose of the cell queuing mechanism is so you don't have to do things like customize the cell appearance every time it appears in the view. If a cell with that type of appearance is already in the queue, then it should come out of the queue already set up, and you only need to put the data into it. This is done for performance (speed), but it may not make a lot of difference in your case. </p> <p>I may be wrong about this, and I'll correct my answer if I am, but the error message may be because the number of sections returned by <code>numberOfSections</code> and/or the number or rows returned by <code>numberOfRowsInSection:</code> is not correct and doesn't match the data source. It is trying to access an element of the data source that doesn't exist. </p> <p>What kind of data source are you using, and can you show the code for <code>numberOfSections</code> and <code>numberOfRowsInSection:</code>?</p> <h2>UPDATE with Correction</h2> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"]; UIView *cellBackView; // move this outside of the switch block switch (indexPath.section) { case 0: [[cell textLabel] setText:title]; [[cell textLabel] setTextColor:[UIColor whiteColor]]; [[cell detailTextLabel] setText:[NSString stringWithFormat:@"Entry: £%@",price]]; [[cell detailTextLabel] setTextColor:[UIColor colorWithWhite:1.0 alpha:.8]]; cell.selectionStyle = UITableViewCellSelectionStyleNone; break; case 1: cellBackView = [[UIView alloc] initWithFrame:CGRectZero]; cellBackView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"PhotoFrame.png"]]; cell.backgroundView = cellBackView; [lImage setFrame:CGRectMake(0, 23, 320, 200)]; [cell.contentView addSubview:lImage]; break; case 2: cellBackView = [[UIView alloc] initWithFrame:CGRectZero]; cellBackView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"PaperTop.png"]]; cell.backgroundView = cellBackView; break; case 3: cellBackView = [[UIView alloc] initWithFrame:CGRectZero]; cellBackView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"Paper.png"]]; cell.backgroundView = cellBackView; break; case 4: cellBackView = [[UIView alloc] initWithFrame:CGRectZero]; cellBackView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"PaperBottom.png"]]; cell.backgroundView = cellBackView; break; default: break; } return cell; } </code></pre>
 

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