views:

761

answers:

1

I have a nib that contains two TableViews. The table views are of the same class that I have created that is a subclass of a UITableViewController. I believe that everything is hooked up correctly. However, when I set the UITableView to the UITableViewController then run

[uitableviewcontrollervariablename reloadData];

I first get a warning that the class may not respond to reloadData. I thought all UITableViewControllers had a reloadData class?

I am trying to hook up these items incorrectly?

Update with code: TopicViewController.h

@interface TopicViewController : UIViewController {
    NSInteger topicID;
    Topic *topic;

    IBOutlet ThoughtTableViewController *featured;

}

@property (retain) Topic *topic;
@property (readonly) NSInteger topicID;
@property (retain) IBOutlet ThoughtTableViewController *featured;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil ID:(NSInteger)ID;

@end

TopicViewController.m

@implementation TopicViewController

@synthesize topic;
@synthesize topicID;
@synthesize featured;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil ID:(NSInteger)ID {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
     topicID = ID;
    }
    return self;
}

- (void)dealloc {
    [topic release];
    [super dealloc];
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    topic = [[Topic alloc] initWithID:topicID];

    NSArray *thoughts = [topic getFeaturedThoughts];
    featured = [[ThoughtTableViewController alloc] initWithStyle:UITableViewStylePlain thoughts:thoughts];
    [self.featured.tableView reloadData];
}

@end
+6  A: 

Your hookups are fine… you just have to call that method on the TableView class, not the controller:

[uitableviewcontrollervariablename.tableView reloadData];

EDIT: 10/20/09
Its kind-of tough to see what is going on because you are using IB instead of programatically adding the tables but the hookups should be like this:

  • UIViewController owns two UITableViews, not two UITableViewControllers
  • UIViewController acts as a UITableViewDataSource, UITableViewDelegate
  • Asking each of the tableViews to reload will ask the DataSource for data, in which you will have to differentiate between the two

Here is some code as an example how to do it programatically:

@interface WhateverController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
    …
    UITableView *tableView1;
    UITableView *tableView2;
}
@end

-

@implementation WhateverController

…

- (void)loadView {
    [super loadView];
    tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(YOUR_FRAME_1)];
    tableView2 = [[UITableView alloc] initWithFrame:CGRectMake(YOUR_FRAME_2)];
    tableView1.delegate = self;
    tableView2.delegate = self;
    tableView1.dataSource = self;
    tableView2.dataSource = self;
    [self.view addSubview:tableView1];
    [self.view addSubview:tableView2];

}

-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == tableView1) {
        // return a cell using the data for tableView1
    } else if (tableView == tableView2) {
        // return a cell using the data for tableView2
    }
}

So you will add all the UITableViewDelegate methods and UITableViewDataSource methods you will need to populate the 2 tableViews. When you want to reload the data:

[tableView1 reloadData];
[tableView2 reloadData];
coneybeare
Thanks. This took care of the warning message. However, the problem still exists that no data is being shown. Do I need to run some kind of an update on the view that contains the uitableview?
Jason
Please update to show any relevant UITableViewController code as it sounds like something is not hooked up right after all
coneybeare
updated with code
Jason
updated answer with code and clarification
coneybeare