简体   繁体   English

segue表视图以查看控制器和表视图

[英]segue table view to view controller and table view

Sorry, i'm new in IOS development. 抱歉,我是IOS开发的新手。

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. 1个单元格将连接到表视图,而其他4个单元格将连接到视图控制器。

From the code below, cell "Attraction" will segue to table view and the other cell will segue to view controller. 从下面的代码中,单元格“ Attraction”将选择到表视图,另一个单元格将选择到视图控制器。

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 . 相反,您必须实现didSelectRowAtIndexPath并通过performSegueWithIdentifier在代码中执行segue。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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