Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Probably you don't want to release it immediately if you:</p> <ul> <li>use didSelectRowAtIndexPath: method for detail views and pass this data to them</li> <li>define custom UITableViewCell styles in cellForRowAtIndexPath: method</li> <li>use this data elsewhere</li> </ul> <p>Best practice is declare an instance variable and synthesize it in .m, use in appropriate operations and release in dealloc method.</p> <p>One possible release point that you could use is where you refresh your data that shown on table.</p> <h2>Example:</h2> <p>I get dictionaries in an array from an API in my app and use something like that.</p> <h3>MyTableViewController.h</h3> <pre><code>@interface MyTableViewController { NSMutableArray *items; } @property (nonatomic, retain) NSMutableArray *items; @end </code></pre> <h3>MyTableViewController.m</h3> <pre><code>@implementation MyTableViewController @synthesize items; - (void)dealloc { [items release]; [super dealloc]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [items count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"FilesCellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; } cell.textLabel.text = [[items objectAtIndex:indexPath.row] valueForKey:@"name"]; cell.imageView.image = [UIImage imageNamed:[[NSString alloc] initWithFormat:@"filetype_%@.png", [[items objectAtIndex:indexPath.row] valueForKey:@"type"]]]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MyDetailViewController *detailViewController = [[MyDetailViewController alloc] initWithNibName:@"MyDetailViewController" bundle:[NSBundle mainBundle]]; detailViewController.item = [items objectAtIndex:indexPath.row]; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; detailViewController = nil; } } - (void)getItems { [items release]; items = [[NSMutableArray alloc] init]; //Do some requests here for (NSDictionary *dict in results) { [items insertObject:dict atIndex:0]; } [self.tableView reloadData]; [self stopLoading]; } @end </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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