![](/img/trans.png)
[英]Is any event other than PopViewController raised on UINavigationController on page pop?
[英]UINavigationController in any other class
嗨,我正在嘗試使UINavigationController而不是在mainViewController(first viewControllerClass)中,我需要將UINavigationController放在第二類中。 但是如果我要在appDelegate.m中編寫這些代碼
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
// [window addSubview:[navigationController view]];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
然后,UINavigationController出現在mainView中。 我試圖把它放在這樣的其他班級
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// strWhichTaleOnScreen=[masivTaleNames objectAtIndex:indexPath.row];
NSString *selectDay;
selectDay=@"first string";
NSLog(@"selecDay=%@",selectDay);
classDetailOfMessagesViewController *nesneDetailOfMessagesViewController = [[classDetailOfMessagesViewController alloc] initWithNibName:@"classDetailOfMessagesViewController" bundle:nil];
nesneDetailOfMessagesViewController.selectDay = selectDay;
[navigation pushViewController: nesneDetailOfMessagesViewController animated:YES];
nesneDetailOfMessagesViewController = nil;
}
但這是行不通的,我想我必須在第二個視圖中創建rootViewController,但我不知道如何。 如果有人可以向我展示解決問題的方法,我會很高興。
我看到的第一個錯誤是您嘗試兩次設置窗口rootviewcontroller。 視圖層次結構需要類似於window-> navigation controller-> view controller。 因此我對您的代碼進行了一些更改。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
在第二個代碼示例中,我找不到導航的引用。 並且如果您將一個視圖控制器(在本例中為initWithRootViewController)推入navigationcontroller堆棧,則可以通過self.navigationController訪問該導航控制器,因此代碼的第二部分應如下所示;
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectDay;
selectDay=@"first string";
NSLog(@"selecDay=%@",selectDay);
classDetailOfMessagesViewController *nesneDetailOfMessagesViewController = [[classDetailOfMessagesViewController alloc] initWithNibName:@"classDetailOfMessagesViewController" bundle:nil];
nesneDetailOfMessagesViewController.selectDay = selectDay;
[self.navigationController pushViewController: nesneDetailOfMessagesViewController animated:YES];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.