【发布时间】:2012-03-07 04:17:17
【问题描述】:
我有一个符合多个代表的UIViewController - 如下所示:
@interface SpotController : UIViewController <UITabBarDelegate, UITableViewDelegate, UITableViewDataSource, MKMapViewDelegate, UIActionSheetDelegate, UINavigationControllerDelegate>
由于某种原因,NavigationControllerDelegate 部分无法正常工作。我不确定我做错了什么。基本上,我正在尝试在选择表查看的行时拨到新的ViewController。我有以下代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *selectedIndexPath = [tableView_ indexPathForSelectedRow];
// do some stuff here to prep/set stuff on the destination VC
DetailsVC *detailsVC = [self.storyboard instantiateViewControllerWithIdentifier:@"detailsVC"];
[self.navigationController pushViewController:detailsVC animated:YES];
}
所以,就像我说的,pushViewController 不起作用,这意味着我没有被发送到目标 VC。我就是不去哪里。
注意:如果我将 ViewController 嵌入到 NavigationController 中(即在 StoryBoard 中选择 VC,然后选择 Editor | Embed In | Navigation Controller),则此确切代码可以完美运行。 但我不想这样做。
我还尝试创建UINavigationController 类型的@property,然后在viewDidLoad 中对其进行分配初始化。我尝试了该方法的init 和initWithRootViewController:self 版本,但都没有奏效。不确定我是否做得对。
也许我需要明确指定@property 作为委托?不知道该怎么做,我尝试了以下操作:
@synthesize navController = navController_;
- (void)viewDidLoad
{
[super viewDidLoad];
navController_ = [[UINavigationController alloc] init]; // initWithRootViewController:self];
[navController_ setDelegate:self];
}
但还是一无所获。
PS - 我正在使用带有 ARC 和 Storyboard 的 Xcode 4.3。
【问题讨论】:
-
如果您使用情节提要,为什么不在情节提要中创建推送转场,然后使用 [self performSegueWithIdentifier:@"identifier" sender:self]?导航控制器的东西应该会自动为您控制。
-
那太容易了 :) 实际上,由于多种原因,我真的不能这样做。 A) 屏幕的某些区域是以编程方式创建的,因此情节提要上没有可连接的对象。 B)类中的某些区域由 if 语句组成,并根据某些条件,推送到一个 VC 或另一个。
标签: objective-c ios cocoa-touch delegates pushviewcontroller