我有一个大问题:在方法 didSelectRowAtIndexPath 上,self.navigationController 总是为 null。我有一个基于 SplitViewController 的项目,我想在详细信息 TableView 中选择一行时推送另一个视图。
建筑学:
LoginView->SplitViewController->Master
->Detail->AnotherView
我的 AppDelegate.m :加载登录表单
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Initialize the app window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
AuthentificationViewController *authentificationViewController =[[AuthentificationViewController alloc] initWithNibName:@"AuthentificationView" bundle:nil];
self.window.rootViewController=authentificationViewController;
[authentificationViewController setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self.splitViewController presentModalViewController:authentificationViewController animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
AppDelagate 的内部接口我有这些属性:
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
方法句柄当我们单击登录表单上的取消按钮时
- (IBAction)btnCancel:(id)sender {
AppDelegate* app_delegate=[[UIApplication sharedApplication] delegate];
//self.window = [[UIApplication sharedApplication] keyWindow];
app_delegate.window.rootViewController= app_delegate.splitViewController;
}
当我们选择一行时,我们有这个方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([indexPath row] == 0)
{
// show add bookmark controller
BookmarkEditorController* bookmarkEditorController = [[[BookmarkEditorController alloc] initWithBookmark:[[ComputerBookmark alloc] initWithBaseDefaultParameters]] autorelease];
[bookmarkEditorController setTitle:NSLocalizedString(@"Ajouter Connexion", @"Add Connection title")];
[self.navigationController pushViewController:bookmarkEditorController animated:YES];
}
但是当我选择一行并且 navigationController 为 nil 时什么都没有发生,请问我该如何解决?
提前致谢
编辑:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *localdetailViewController =nil;
if([indexPath row] == 0)
{
// show add bookmark controller
BookmarkEditorController* bookmarkEditorController = [[[BookmarkEditorController alloc] initWithBookmark:[[ComputerBookmark alloc] initWithBaseDefaultParameters]] autorelease];
[bookmarkEditorController setTitle:NSLocalizedString(@"Ajouter Connexion", @"Add Connection title")];
localdetailViewController=bookmarkEditorController;
AppDelegate *delegate =[[UIApplication sharedApplication] delegate];
NSArray *viewControllers=[[NSArray alloc] initWithObjects: [delegate.splitViewController.viewControllers objectAtIndex:0],bookmarkEditorController,nil];
delegate.splitViewController.viewControllers=viewControllers;
}
}