Arian Faurtosh
Arian Faurtosh

Reputation: 18511

How to send a next button, to a UITableView

I am trying to get a UITableView to show up after I tap a next button, I can't get it to work...

I don't know why TimesViewController.m isn't working, how do I link it...

-(IBAction)nextView:(UIBarButtonItem *) sender{

    [self pushViewController:TimesTableViewController.m animated:YES];

}

Upvotes: 0

Views: 54

Answers (2)

rivtracks
rivtracks

Reputation: 43

or if you wanna do it programmatically, in your viewDidLoad, after you created your button

[firstsessionButton addTarget:self action:@selector(showtable:) forControlEvents:UIControlEventTouchUpInside];

-(void)showtable:(UIButton *)sender{
TableViewController *tableViewController=[[TableViewController alloc]init];
[self.navigationController pushViewController:tableViewController animated:YES];
}

Upvotes: 0

Abhinav
Abhinav

Reputation: 38162

You need to read through View Controller programming guide. Essentially, it depends more on your application design. The most common ways of doing this are:

  1. Tap on nextView should present TableView controller modally.
  2. Tap on nextView should push TableView controller in the navigation stack.

With either of the approach, you need to create a separate view controller for your table view which will manage the table view and act as delegate/data source for it.

From within your button action handler you need to do it this way:

-(IBAction)nextView:(UIBarButtonItem *) sender{
    MyTableViewController *tableController = [[MyTableViewController alloc] init];

    // For #1 above
    [self presentViewController:tableController animated:YES completion:^{
        // Any code that you want to execute once modal presentation is done
    }];

    // For #2 above
    [self.navigationController pushViewController:tableController animated:YES];
}

EDIT:

Create a initialize method on your MyTableViewController and pass the values while calling it.

- (id)initWithData1:(NSString *)iData1 data2:(NSString *)iData2 {
    if ((self = [super init])) {
        self.data1 = iData1;
        self.data2 = iData2;
    }
    return self;
}

MyTableViewController *tableController = [[MyTableViewController alloc] initWithData1:@"Some String" data2:@"Another string"];

PS: You could also expose the string property in your header file of MyTableViewController and set it from the callee class

Upvotes: 3

Related Questions