Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone SDK: Inserting and updating a UITableView with a new row
    text
    copied!<p>I have a tableView that needs to be updated after information has been inserted from another view. If I perform a </p> <pre><code>[self.tableView reloadData]; </code></pre> <p>The very next time I insert more information in another view and try to reload the table, all the currently visible rows are duplicated.</p> <p>In other words, when I start up the app I have:</p> <pre><code>tableView: Row 1 Row 2 </code></pre> <p>Then I submit some information that will also show up in the table and suddenly I have:</p> <pre><code>tableView Row 1 Row 2 Row 3 &lt;- info I just added Row 1 Row 2 </code></pre> <p>My numberOfRowsInSection implementation looks like this:</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [ItemsController sharedItemsController].count; } </code></pre> <p>My cellForRowAtIndexPath implementation looks like this:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ItemsController* controller = [ItemsController sharedItemsController]; NSMutableArray* recentItems = controller.listOfRecentItems; CustomCell *cell = nil; NSUInteger row = [indexPath row]; if( row &lt; recentItems.count ) { Items* item = [recentItems objectAtIndex:row]; if( recentCellData == nil ) recentCellData = [[NSMutableDictionary alloc] initWithCapacity:[indexPath length]]; if( [recentCellData count] &gt; 0 ) cell = [recentCellData objectForKey:[NSString stringWithFormat:@"%d", row]]; if (cell == nil) { UIViewController * view1 = [[UIViewController alloc] initWithNibName:@"CustomCell" bundle:nil]; cell = (CustomCell*)[view1 view]; [recentCellData setObject:cell forKey:[NSString stringWithFormat:@"%d",row]]; } // do some other stuff here } // Set up the cell return cell; } </code></pre> <p>What's the best way to update the table and avoid duplicating the currently visible rows. Thank in advance for all the help!</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