pushViewController不使用标签栏控制器

use*_*985 2 xcode objective-c uitabbarcontroller uinavigationcontroller pushviewcontroller

我试图用代码推入一个新的视图控制器:

[self.navigationController pushViewController:webViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)

但它不起作用.在表视图中选择单元格时会发生此代码.我有一个表视图,我认为这是防止这种情况发生的.我试过以模态方式呈现它,但摆脱了导航栏,我不能回去.有一个非常类似于此但答案对我不起作用!

UPDATE

- (void)loadView {
    // Create an instance of UIWebView as large as the screen
    CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
    UIWebView *wv = [[UIWebView alloc] initWithFrame:screenFrame];
    // Tell web view to scale web content to fit within bounds of webview 
    [wv setScalesPageToFit:YES];

    [self setView:wv];
    [wv release];
}
Run Code Online (Sandbox Code Playgroud)

将Web视图作为WebViewController的视图

如上所示没有笔尖

使用NSLog查询didSelect单元格方法以查找

一切都被初始化和分配,非零

更新:

我做了选择细胞方法:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Push the web view controller onto the navigaton stack - this implicity
    // creates the web view controller's view the first time through

    NSLog(@"TOUCHED!");

    webViewController = [[WebViewController alloc] init];

    if (webViewController == nil) {
        NSLog(@"webViewController in nil state");
    }

    [self.navigationController pushViewController:webViewController animated:YES];


    // Grab the selected item
    RSSItem *entry = [[channel items] objectAtIndex:[indexPath row]];

    // Construct a URL with the link string of the item
    NSURL *url = [NSURL URLWithString:[entry link]];

    // Construct a request object with that URL
    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    // Load the request into the web view
    [[webViewController webView] loadRequest:req];

    // Set the title of the web view controller's navigation item
    [[webViewController navigationItem] setTitle:[entry title]];

}
Run Code Online (Sandbox Code Playgroud)

所有这些都在插入TAB BAR控制器之前工作

UPDATE

我在哪里创建控制器(IN APP DELEGATE):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

             self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    ListViewController *lvc = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];

    [lvc autorelease];
    // Create the tabBarController
    UITabBarController *tabBarController = [[UITabBarController alloc] init];

    // Create two view controllers
    UIViewController *vc1 = [[ListViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UIViewController *vc2 = [[YoutubeViewController alloc] init];

    // Make an array containing the two view controllers
    NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil];

    // The viewControllers array retains vc1 and vc2, we can release
    // our ownership of them in this method
    [vc1 release];
    [vc2 release];

    // Attach them to the tab bar controller
    [tabBarController setViewControllers:viewControllers];

    // Put the tabBarController's view on the window
    [[self window] setRootViewController:tabBarController];

    // The window retains tabBarController, we can release our reference
    [tabBarController release];

    // Show the window
    [[self window] makeKeyAndVisible];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

所以我真的不知道这里发生了什么.如果您可以帮我解决另一个问题!转到我的个人资料,查看有关如何停止截止/在uitableviewcell中为文本标签添加额外行的问题

小智 5

我没有在你的app委托中看到最初的UINavigationViewController.为了使用self.navigationController pushViewController,视图控制器需要位于self.navigationController.viewControllers中.你可以修改你的代码并尝试以下内容,看看它是否适合你.

// Create two view controllers
UIViewController *vc1 = [[ListViewController alloc] initWithStyle:UITableViewStyleGrouped];
UIViewController *vc2 = [[YoutubeViewController alloc] init];

// Create the UINavigationController and put the list view controller as the root view controller
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc1];

// Make an array containing the two view controllers and the UINavigationController which has the ListViewController is the first one.
NSArray *viewControllers = [NSArray arrayWithObjects:navController, vc2, nil];

// The viewControllers array retains vc1 and vc2, we can release
// our ownership of them in this method
[vc1 release];
[vc2 release];
[navController release];

// Attach them to the tab bar controller
[tabBarController setViewControllers:viewControllers];
Run Code Online (Sandbox Code Playgroud)