Keaton
Keaton

Reputation: 127

Multiple TableViews in a Single View Xcode

I have one view that has two tableviews, I want one of them to be a twitter feed and the other an RSS feed. The problem is they show up exactly the same, same content. I have tried using another controller, but I cannot do that because i cannot figgure it out.

Upvotes: 0

Views: 465

Answers (1)

Richard
Richard

Reputation: 61

Not sure if you are still looking for the answer to your question, but in any case it may be helpful for others too. I have tried the following with success: You can use a separate tableviewcontroller for each tableview. In your viewDidLoad you can alloc init your tableviewcontrollers and then set the tableview's datasource and delegate to be your respective tableviewcontrollers. Finally, set the view of your controllers to be the tableview of your tableview controller. The following code shows what I mean:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // ...
    if(!self.tweeterTableViewController)
    {
        self.tweeterTableViewController = [[TweeterTableViewController alloc] init];
    }
    if(!self.rssTableViewController)
    {
        self.rssTableViewController = [[RssTableViewController alloc] init];
    }

    [self.tweeterTableView setDataSource:self.tweeterTableViewController];
    [self.tweeterTableView setDelegate:self.tweeterTableViewController];
    self.tweeterTableViewController.view = self.tweeterTableViewController.tableView;

    [self.rssTableView setDataSource:self.rssTableViewController];
    [self.rssTableView setDelegate:self.rssTableViewController];
    self.rssTableViewController.view = self.rssTableViewController.tableView;

    // ...
}

Upvotes: 6

Related Questions