Tefa Mohamed
Tefa Mohamed

Reputation: 23

PushViewController in tableview

In My App My Root View Controller is TabBar in one Of TabBar Controller i Use table View i wanna push View Controller when Press To Cell but when i use

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

doesn't do any thing this because Self.navigation=null

and i try to Create UINavigationController in AppDelegate

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

My 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;
}

and this doesn't work what i can do ? Thanks In Advance

Upvotes: 0

Views: 398

Answers (2)

Midhun MP
Midhun MP

Reputation: 107231

You need to create an Instance of UINavigationController inside your appdelegate. And you need to add a navigation bar in your view in the tab bar controller.

If you have a tab bar in the xib, drag a UINavigationController object over from the Library window into the Tree View for your tab bar. Place the navigation controller inside the tab bar controller, then drag your existing view controller inside the navigation controller.

If you are creating the tabbar programmatically it's quite simple:

Do like:

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];

Please refer this tutorial

Upvotes: 1

miho
miho

Reputation: 12085

You need to use an UINaviatigationController as your applications root view controller and then add the first table view as the navigation root view of the navigation controller. Then you can push other table views with [self.navigationController pushViewController:animated:].

Upvotes: 0

Related Questions