本文介绍了Xcode 4.2 iOS 5:来自UITableView的多个segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在开始使用Xcode for 4.2 for iOS5并且有一些变化,我现在遇到了一个我无法找到解决方法的问题。

I'm starting now with Xcode on 4.2 for iOS5 and there are a few changes and I'm now crossing a problem that I can't figure out a way to solve it.

我正在用UITablwView做一个例子,它以2个部分编程填充,第1部分只有1行,第2部分有3行。

I'm doing an example with a UITablwView that is populated programmatically with 2 Sections, 1st section with only 1 Row, and 2nd Section with 3 Rows.

我的目标是从表中选择一行,并根据该行,用户将被重定向到不同的视图。

My aim is to select a row from the table, and based on that row, the user will be redirected to different Views.

例如:
选择第0行0,app推送查看1 - 名称设置//
选择第1行0,app推送查看3 - 地址设置

For example:selecting section 0 row 0, app pushes to view 1 - name setting //selecting section 1 row 0, app pushes to view 3 - address setting

旧的时尚方式,这很简单,只需要用initWithNibName初始化一个UIViewController然后推送视图。

The old fashion way, this is quite simple, just needed to init a UIViewController with initWithNibName and then push the view.

现在有了storyBoard所有的变化,或者至少我认为它改变,因为我无法看到如何得到相同的结果,因为我无法从tableView设置多个segue到不同的UIViewControl lers ...并且做旧的时尚方式我无法看到我可以从storyBoard上的视图中获取NIB名称以初始化UIViewController来推送。

Now with the storyBoard everything changes, or at least I think it changes because I can't see how to get the same result since I can't set multiple segue's from the tableView to different UIViewControllers...and to do the old fashion way I can't see where I can get the NIB names from the views on the storyBoard to init an UIViewController to push.

有没有人知道如何得到这个结果?

Does any one knows how to get to this result??

推荐答案

定义两个通用segue(标识为segue1)和来自源视图控制器的故事板中的segue2,例如,一个到每个目标视图控制器。这些segue不会与任何操作相关联。

Define two "generic" segues (identified as "segue1" and "segue2", for example) in the storyboard from your source view controller, one to each destination view controller. These segues won't be associated with any action.

然后,有条件地执行 UITableViewDelegate 中的segues:

Then, conditionally perform the segues in your UITableViewDelegate:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Conditionally perform segues, here is an example:
    if (indexPath.row == 0)
    {
        [self performSegueWithIdentifier:@"segue1" sender:self];
    }
    else
    {
        [self performSegueWithIdentifier:@"segue2" sender:self];
    }
}

这篇关于Xcode 4.2 iOS 5:来自UITableView的多个segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:29