Note that there are some explanatory texts on larger screens.

plurals
  1. POcellForRowAtIndexPath: for StoryBoard and XIB Behaviour and Cell caching mechanism?
    text
    copied!<p>I am new in iOS Development. I do not understand behaviour of tableView. <br/> To test it, I have made two Simple tableView application and I have loaded tableView with 99999 rows with standard code snippet in both cases , if user scrolls down till the end of tableView.</p> <p><br/> <strong>App 1 : TableViewWithStoryBoard cellForRowAtIndexPath: code snippet</strong></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // for StoryBoard if (cell == nil) { static int i; NSLog(@"New Cells created: %d ",++i); cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row]; return cell; </code></pre> <p>}</p> <p><strong>Question 1:</strong> If I remove </p> <pre><code>forIndexPath:indexPath from UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // for StoryBoard </code></pre> <p>then StoryBoard still functions properly in simulator? Then why it has been provided ?</p> <p><strong>Question 2:</strong> Why NSLog(@"New Cells created: %d ",++i); never gets printed even if i scroll down to 99999 rows that is end of my tableView? In what scenario NSLog will print some values ? </p> <p><br/> <br/></p> <p><strong>App 2: TableViewWithNib cellForRowAtIndexPath: code snippet</strong></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // for Nib File if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row]; return cell; </code></pre> <p>}</p> <p><strong>Question 3:</strong> If I add </p> <pre><code>forIndexPath:indexPath </code></pre> <p>in the XIB Version then my application crashes and throws an Exception? Why is it so ? <br/> <br/> Exception or Error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'</p>
 

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