Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you setup the UITableViewCell in <code>tableView:cellForRowAtIndexPath:</code>, you're using data from a certain index in the array of results, based on the index path of the cell.</p> <p>The easiest way to do what you ask is to use the index path for the selected cell and perform the same calculation as above to find that certain index. Then you can fetch everything you need from the original array. That would look something like this:</p> <pre><code>- (NSUInteger)arrayIndexFromIndexPath:(NSIndexPath *)path { // You could inline this, if you like. return path.row; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)path { NSUInteger index = [self arrayIndexFromIndexPath:path]; NSDictionary *data = [self.dataArray objectAtIndex:index]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:...]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:... reuseIdentifier:...] autorelease]; } // ... Set up cell ... return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path { NSUInteger index = [self arrayIndexFromIndexPath:path]; NSDictionary *data = [self.dataArray objectAtIndex:index]; // ... Do whatever you need with the data ... } </code></pre> <p>A slightly more complex (but possibly more robust) method would be to subclass UITableViewCell to add properties or ivars to hold the data you will need; this could be as simple as a single property to hold the entire value from the original array. Then in the selection method, you can fetch everything you need from the cell itself. That would look something like this:</p> <p>MyTableViewCell.h:</p> <pre><code>@interface MyTableViewCell : UITableViewCell { NSDictionary *data_; } @property (nonatomic, retain) NSDictionary *data; @end </code></pre> <p>MyTableViewCell.m:</p> <pre><code>@implementation MyTableViewCell @synthesize data=data_; - (void)dealloc { [data_ release]; data_ = nil; [super dealloc]; } @end </code></pre> <p>And then:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)path { NSUInteger index = [self arrayIndexFromIndexPath:path]; NSDictionary *data = [self.dataArray objectAtIndex:index]; // Remember, of course, to use a different reuseIdentifier for each different kind of cell. MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:...]; if (!cell) { cell = [[[MyTableViewCell alloc] initWithStyle:... reuseIdentifier:...] autorelease]; } cell.data = data; // ... Set up cell ... return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path { MyTableViewCell *cell = [tableView cellForRowAtIndexPath:path]; NSDictionary *data = cell.data; // ... Do whatever you need with the data ... } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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