user1958756
user1958756

Reputation: 377

non-Custom UITableViewCells disappear on click or Scroll

I have a tableview that I'm populating from an NSArray and whenever I click on or scroll the table all the TableCells go away. AFAICT there's no problem with the cell reuse identifiers and the rowList NSArray isn't doing anything funny either. Here's the relevant code. "click" never shows up in the log.

@interface TheTableViewController ()
@property (strong,nonatomic) NSArray * rowList;
@end

@implementation TheTableViewController
@synthesize rowList;

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [rowList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath {
    NSString *cid = [@"" stringByAppendingFormat:@"CellReuseIdentifier_%i",indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cid];
    cell = cell ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cid];
    cell.textLabel.text = [rowList objectAtIndex:indexPath.row];
    return cell;
}

#pragma mark - table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"click");
}
@end

Upvotes: 2

Views: 421

Answers (1)

user1958756
user1958756

Reputation: 377

It turns out the problem was nowhere near where I thought it was. A co-worker pointed out that the tableview's delegate and datasource was getting released. I'm including the answer here in case anyone ever has/hears of a similar problem or is curious.

-(IBAction)ButtonAction:(id)sender {
    UITableViewController * t = [UITableViewController new];
    [self.view addSubview:t.view];
    [UIView animateWithDuration:0.50 animations:^{t.view.frame = CGRectMake(0,0,640,480}]
};

The fix was to make "t" a property so it sticks around until we get rid of it.

@interface MainViewController: <
@property (strong,nonatomic) UITableViewController * t;
@end

@implementation MainViewController ()
@synthesize t;

-(IBAction)ButtonAction:(id)sender {
    UITableViewController * t = [UITableViewController new];
    [self.view addSubview:t.view];
    [UIView animateWithDuration:0.50 animations:^{t.view.frame = CGRectMake(0,0,640,480}]
};

Upvotes: 3

Related Questions