UINavigationController in any other class - ios

Hi i am trying to make UINavigationController but not in mainViewController(first viewControllerClass) , i need to put UINavigationController in second class. But If i will write these codes in 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;
}
Then UINavigationController appears in mainView. I am trying to put it in other class like that
-(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;
}
But it doesn't work, I guess i have to create rootViewController in this second view but i dont know how.
I ll be happy if someone can show me way to solve it out.

The first mistake i saw was you are trying to set the window rootviewcontroller twice. The view hierarchy needs to be like window->navigation controller->view controller. so I made some changes with your code.
- (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;
}
In the second code sample I couldn't find the reference to the navigation. And also if you push (in your case initWithRootViewController) a view controller to navigationcontroller stack you can access the navigation controller by self.navigationController so your second part of the code should be like this;
-(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];
}

Related

MFSideMenu side Viewcontroller not navigate to Specific view controller in Tabbarcontroller

I am using MFSideMenu in TabBarController In SideMenu i have added UITableview so when i click on cell then it navigate to another view controller but its not navigate to that view controller
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
centerViewController = [storyboard instantiateViewControllerWithIdentifier:#"Tabbarcontroller"];
TabViewController1 *tableView = [storyboard instantiateViewControllerWithIdentifier:#"TabViewController1"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tableView];
TabViewController2 *tableView2 = [storyboard instantiateViewControllerWithIdentifier:#"TabViewController2"];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tableView2];
centerViewController.viewControllers = #[nav1,nav2];
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"SideViewController"];
container = [MFSideMenuContainerViewController
containerWithCenterViewController:centerViewController
leftMenuViewController:leftSideMenuViewController
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
}
SideMenu.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewController3 *objEdit =[self.storyboard instantiateViewControllerWithIdentifier:#"ViewController3"];
AppDelegate *objApp = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UINavigationController *navigationController = (UINavigationController *) objApp.centerViewController.navigationController;
NSLog(#"navigationcontroller :%#",objApp.centerViewController.navigationController);
[navigationController pushViewController:objEdit animated:YES];
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
objApp.centerViewController is tabbarcontroller, So you need to find out selected view controller from tabor controller first. If you want to push controller in selected tab, You should get Navigationcontroller from SelectedViewCOntroller of tabbarcontroller.
UINavigationController *navigationController = (UINavigationController *) objApp.centerViewController.selectedViewController;
[navigationController pushViewController:objEdit animated:YES];

Choose which ViewController will display initially

I'm trying to select which ViewController the AppDelegate should display based in a NSUserDefaults BOOL. But the HomeViewController does not display.
I'm using Storyboards and I have my own class of UINavigationController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBLoginView class];
[FBProfilePictureView class];
MeuNavigationController *nav = [[MeuNavigationController alloc]init];
if ([NSUD boolForChave:#"firstLogin"]==false) {
ViewController *viewC = [[ViewController alloc]init];
[nav pushViewController:viewC animated:NO];
}else{
HomeViewController *viewP = [[HomeViewController alloc]init];
[nav pushViewController:viewP animated:NO];
}
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBLoginView class];
[FBProfilePictureView class];
UIViewController *controller = nil;
if ([NSUD boolForChave:#"firstLogin"]==false) {
controller = [[ViewController alloc]init];
}else{
controller = [[HomeViewController alloc]init];
}
self.window.rootViewController = [[MenuNavigationController alloc] initWithRootViewController:controller];
[self.window makeKeyAndVisible];
return YES;
}
You noted that you're doing this off of storyboard. You might want to consider making this change as well:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBLoginView class];
[FBProfilePictureView class];
// Name of storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *controller = nil;
if ([NSUD boolForChave:#"firstLogin"]==false) {
controller = [[ViewController alloc]init];
// Set this in the storyboard's identity inspector
controller = [storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
}else{
controller = [storyboard instantiateViewControllerWithIdentifier:#"HomeViewController"];
}
self.window.rootViewController = [[MenuNavigationController alloc] initWithRootViewController:controller];
[self.window makeKeyAndVisible];
return YES;
}
But you ask... Mr. jakenberg, how does one set their unique view controller identifier?
Cheers

Detailed view controller not showing from uilistview didSelect event

didSelectRowAtIndexPath: is firing but the view controller is not. I have tried different view controllers that I know are working. Since the method is firing then I can only speculate that
[self.navigationController pushViewController:detailVC animated:YES];
is not reaching the navigation stack.
But I call the Calendar View Controller from a tabbarcontroller so I do not know what to do to fix this.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
GlobalSingleton *myAppID = [GlobalSingleton sharedSingleton];
myAppID.globalAppID = #"627";
UIViewController *calendarVC;
calendarVC = [[[CalendarViewController alloc] initWithNibName:#"CalendarViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[calendarVC];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
self.tabBarController.customizableViewControllers = nil;
return YES;
}
CalendarViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Row %#",[events objectAtIndex:indexPath.row] );
CalendarDetailVC *detailVC = [[CalendarDetailVC alloc] initWithNibName:#"CalendarDetailVC" bundle:nil];
detailVC.dictEvent = [events objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailVC animated:YES];
}
You don't have a navigation controller in your hierarchy, so you can't so a push. You need to add a line to create the navigation controller,
calendarVC = [[[CalendarViewController alloc] initWithNibName:#"CalendarViewController" bundle:nil] autorelease];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController: calendarVC] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[nav];

PushViewController with tabBarController not working

I have a tabBar application. One of the tabs has a rootviewcontroller that creates a UITableView and adds it to the subview. When a user clicks a cell in the UITableView I want to push a new rootviewcontroller but I cant get it to work.
In my appDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Create the window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
//Create the UIViewCOntrollers for each tab
_viewController1 = [[[LocavoreRetroFirstViewController alloc] initWithNibName:#"LocavoreRetroFirstViewController" bundle:nil] autorelease];
_viewController2 = [[[LocavoreRetroSecondViewController alloc] initWithNibName:#"LocavoreRetroSecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[LocavoreRetroThirdViewController alloc] initWithNibName:#"LocavoreRetroThirdViewController" bundle:nil] autorelease];
_viewController4 = [[[LocavoreRetroFourthViewController alloc] initWithNibName:#"LocavoreRetroFourthViewController" bundle:nil] autorelease];
UIViewController *viewController5 = [[[LocavoreRetroFifthViewController alloc] initWithNibName:#"LocavoreRetroFifthViewController" bundle:nil] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController1];
//[_viewController1 release];
NSArray* controllers = [NSArray arrayWithObjects:navigationController, _viewController2, viewController3, _viewController4, viewController5, nil];
//Create the tab controller
_tabBarController = [[[UITabBarController alloc] init] autorelease];
[_tabBarController setViewControllers:controllers];
//Initialize the tab controller with the views
// _tabBarController.viewControllers = #[_viewController1, _viewController2,
// viewController3, _viewController4, viewController5];
//Set the window to the tabcontroller view and make it visible
_window.rootViewController = _tabBarController;
_tabBarController.delegate=self;
[_window makeKeyAndVisible];
return YES;
}
In my subview didSelectRowAtIndexPath method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RecipePageController *recipePageController = [[RecipePageController alloc] initWithNibName:#"RecipePageController" bundle:nil];
[self.navigationController pushViewController:recipePageController animated:YES];
[recipePageController release];
}
For each tab you need to create a separate navigation controller

Master detail uisplitViewController and UINavigationController view

I try to push from a detail view to an other view. I have a tableView in a detailView "ConRDPDetailViewController" and I will like that when I click on a row, that push the new view "BookmarkEditorController".
here is my method in "ConRDPDetailViewController" where I try to do that :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ComputerBookmark* bookmark = nil;
if([indexPath section] == SECTION_BOOKMARKS)
{
// first row has either quick connect or add bookmark item
if([indexPath row] == 0)
{
// show add bookmark controller: is there I try to push the new View
BookmarkEditorController* bookmarkEditorController = [[[BookmarkEditorController alloc] initWithBookmark:[[ComputerBookmark alloc] initWithBaseDefaultParameters]] autorelease];
[bookmarkEditorController setTitle:NSLocalizedString(#"Ajouter Connexion", #"Add Connection title")];
UINavigationController *view = [[UINavigationController alloc] initWithRootViewController:bookmarkEditorController];
[view.navigationController pushViewController:bookmarkEditorController animated:YES];
[bookmarkEditorController setDelegate:self];
[bookmarkEditorController setHidesBottomBarWhenPushed:YES];
}
}
}
But nothing is happen, here is my method didFinishLaunchingWithOptions in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self redirectConsoleLogToDocumentFolder];
// Initialize the app window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
AuthentificationViewController *authentificationViewController =[[AuthentificationViewController alloc] initWithNibName:#"AuthentificationView" bundle:nil];
//self.window.rootViewController = self.splitViewController;
self.window.rootViewController = authentificationViewController;
[self.window makeKeyAndVisible];
// The new popover look for split views was added in iOS 5.1.
// This checks if the setting to enable it is available and
// sets it to YES if so.
// if ([self.splitViewController respondsToSelector:#selector(setPresentsWithGesture:)])
// [self.splitViewController setPresentsWithGesture:YES];
return YES;
}
Thank you in advance
You need to embed the table view controller in a navigation controller.
Then you can push the detail view with this code:
BookmarkEditorController* bookmarkEditorController = [[[BookmarkEditorController alloc] initWithBookmark:[[ComputerBookmark alloc] initWithBaseDefaultParameters]] autorelease];
[bookmarkEditorController setTitle:NSLocalizedString(#"Ajouter Connexion", #"Add Connection title")];
[self.navigationController pushViewController:bookmarkEditorController animated:YES];
[bookmarkEditorController setDelegate:self];
[bookmarkEditorController setHidesBottomBarWhenPushed:YES];

Resources