views:

30

answers:

1

I just came across a situation where my implementation of a tableview is working in 3.2 but fails to fire any of the tableview methods in iOS 4. The view controller in question is defined as a UIViewController and is setup to adopt the UITableViewDataSource and UITableViewDelegate protocols, and I'm hooking the tableview up as the view's datasource and delegate via IB.

Definition in .h:

@interface FooViewController : UIViewController <UITableViewDataSource,
    UITableViewDelegate> {

    IBOutlet UITableView *itemTable;
}

@property (nonatomic, retain) IBOutlet UITableView *itemTable;

.m:

@synthesize itemTable;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    NSLog(@"numberOfSectionsInTableView fired!");
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section {
    NSLog(@"numberOfRowsInSection fired!");
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

return cell;
}

This appears to work fine in < 4.0, but in 4 it just simply bypasses firing any of these methods. Am I by chance doing it incorrectly and being caught up by something being fixed in 4.0?

A: 

Do you have the dataSource and delegate set for the itemTable? The rest of your code seems to look fine. Another question is why use the UiViewController instead of using the UITableViewController

I've been using the UITableViewController and it works quite well, and you can still just implement the simple basic methods you have implemented.

christophercotton
WRT datasource/delegate: yes, hooked up via IB.More findings:It appears it only *doesn't* work in iOS 4 when the file owner is pushed on the stack via presentModalViewController. When I push it via a navigation controller, it seems to work fine. I'm pushing via presentModalViewController because it is the screen that slides in for presenting in-app purchase stuff.So the problem has now been refined - the tableView methods don't get called when the parent view controller is pushed via presentModalViewController. This appears to be where it 'broke' in iOS 4...or at least changed behavior.
cg4875