简体   繁体   中英

segue table view to view controller and table view

Sorry, i'm new in IOS development.

I have a table view with five cells.

1 cell will segue to table view and the other 4 cell will segue to view controller.

From the code below, cell "Attraction" will segue to table view and the other cell will segue to view controller.

How do i can do that?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Initialize table data
    mainMenu = [NSArray arrayWithObjects:@"Introduction", @"History", @"Attractions", @"Culture", @"About", nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [mainMenu count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tableIdentifier = @"MainMenuCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
    }

    cell.textLabel.text = [mainMenu objectAtIndex:indexPath.row];
    return cell;
}

Use static table view cells . This is a setting for the table view in interface builder. This is feasible setup because you only have a fixed number of five cells.

If you still need dynamic cells, you cannot use interface builder to assign the segue to a specific cell. Instead, you have to implement didSelectRowAtIndexPath and perform the segue in code via performSegueWithIdentifier .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM