我有一个很大的问题:在方法didSelectRowAtIndexPath上我总是得到null.navigationController.I有一个基于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为零时没有任何事情发生,请问我该如何解决?
提前致谢
编辑:
- (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;
}
}
答案 0 :(得分:1)
看看这个Link ,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController* myVCToReplace = nil;
if(indexPath.row == 1)
myVCToReplace = [myVC1 alloc]init];
else
myVCToReplace = [myVC2 alloc]init];
NSMutableArray* array = [[NSMutableArray alloc] initWithArray:MySplitVC.viewControllers];
[arr replaceObjectAtIndex:1 withObject:myReplacementVC];
MySplitVC.viewControllers = arr;
[arr release];
答案 1 :(得分:1)