【问题标题】:PushViewController in tableview表视图中的 PushViewController
【发布时间】:2012-11-07 13:41:20
【问题描述】:

在我的应用程序中,我的根视图控制器是 TabBar 在一个 TabBar 控制器中我使用表格视图我想在按下单元格时推送视图控制器 但是当我使用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  TripDetailView * TripDetailViewObjec = [[TripDetailView alloc]init];
    [self.navigationController pushViewController:TripDetailViewObjec animated:YES];
}

不这样做是因为Self.navigation=null

我尝试在 AppDelegate 中创建 UINavigationController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AppDelegate * ApplicationDelegate =[[UIApplication sharedApplication]delegate];
        [[ApplicationDelegate Nav] pushViewController:TripDetailViewObjec animated:YES];
}

我的 AppDelegate

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    WeekendTrips * WeekendTripsObject ; 
    UINavigationController * Nav;
}

@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic)   UINavigationController * Nav;
@end

@implementation AppDelegate
@synthesize Nav;

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
WeekendTripsObject = [[WeekendTrips alloc]init];

    Nav=[[UINavigationController alloc]initWithRootViewController:WeekendTripsObject];
   [self.view addSubView Nav.view];
    return YES;
}

这不起作用 我可以做什么 ? 提前致谢

【问题讨论】:

    标签: ios uitableview uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    您需要在您的 appdelegate 中创建一个 UINavigationController 的实例。 并且您需要在标签栏控制器的视图中添加一个导航栏。

    如果您在 xib 中有标签栏,请将 UINavigationController 对象从库窗口拖到标签栏的树视图中。将导航控制器放在标签栏控制器内,然后将现有视图控制器拖到导航控制器内。

    如果您以编程方式创建标签栏,则非常简单:

    喜欢:

    UIViewController *viewController1 = [[UIViewController alloc] initWithNibName:@"yournib1" bundle:nil];
    UINavigationController *navigationcontroller = [[UINavigationController alloc] initWithRootViewController:viewController1];
    
    UIViewController *viewController2 = [[UIViewController alloc] initWithNibName:@"yournib2" bundle:nil];
    
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationcontroller, viewController2, nil];
    

    请参考tutorial

    【讨论】:

    • 真的非常感谢 Midhun ...我问你更多问题直到现在
    • @TefaMohamed:没​​关系,伙计 :)
    【解决方案2】:

    您需要使用 UINaviatigationController 作为应用程序的根视图控制器,然后添加第一个表视图作为导航控制器的导航根视图。然后你可以用[self.navigationController pushViewController:animated:]推送其他表视图。

    【讨论】:

    • 如果我这样做,我的 rootviewcontroller 将更改为 table view,我想保持我的 rootviewcontroller 是 TabBar
    • 我知道这个话题有点混乱,但请仔细阅读。应用的根视图控制器(应该是 UINavigationController)和导航控制器的根视图控制器(应该是 UITableViewController)是有区别的!
    猜你喜欢
    • 1970-01-01
    • 2010-12-13
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 2011-09-14
    • 2011-10-27
    相关资源
    最近更新 更多