Note that there are some explanatory texts on larger screens.

plurals
  1. POCocoa Touch table datasource problem
    primarykey
    data
    text
    <p>I'm having some trouble with displaying results from a datasource. This code will show a different (and correct) result in the console, but results in all kinds of random crap in the simulator.</p> <p>("results" is an NSMutableArray property for the class.)</p> <pre><code>-(void) handleSearchForKeywords: (NSString *) keywords { [results removeAllObjects]; int r = rand() % 10; for( int i = 0; i &lt; r; i++ ) { [results addObject:[NSString stringWithFormat:@"test %i: %@", i, keywords]]; } [self reloadTheTable]; } -(void) reloadTheTable { NSLog( @"current array contents: %@", results ); [tableView reloadData]; }</code></pre> <p>I'm guessing that this might have something to do with memory retention of the array, or the strings in the array? I'm afraid I still haven't got the hang of that.</p> <p>[edit in response to Marc Bessey -- I think everything here is your basic datasource methods]</p> <pre><code>-(NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section { return [results count]; } -(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { static NSString *SearchViewControllerCell = @"SearchViewControllerCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SearchViewControllerCell]; if( cell == nil ) { cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: SearchViewControllerCell] autorelease]; NSUInteger row = [indexPath row]; [cell setText:[results objectAtIndex:row]]; } return cell; }</code></pre>
    singulars
    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. 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