viewControllers that doesn't appear - ios

I have a question for you:
I have a set of UIViewController attached to self.tabBarController.viewControllers
and i have another one alone that is supposed to be the login scree that appear just once (the first time you open the app ever), and i wish to load that one in case the user is not logged in, otherwise or after that the user log in, it will load the full self.tabBarController.viewControllers that i have.
Here is the code:
-(void)load_login_view{
NSLog(#"map");
UIViewController * fb_login = [[FacebookLoginView alloc]init];
fb_login.title = #"fsf ss";
UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login];
[fb_login_navigation.tabBarItem setImage:[UIImage imageNamed:#"eventi.png"]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL login_status = [defaults objectForKey:#"login_status"];
UIViewController * secondpage = [[SecondViewController alloc]init];
secondpage.title = #"second";
UINavigationController * secondpage_navigation = [[UINavigationController alloc] initWithRootViewController:secondpage];
[secondpage_navigation.tabBarItem setImage:[UIImage imageNamed:#"eventi.png"]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[secondpage_navigation];
self.window.rootViewController = self.tabBarController;
if(!login_status){
[self load_login_view];
}else{
}
[self.window makeKeyAndVisible];
}

You have many ways to do that. There is a couple of examples.
With your current navigation flow
-> if the user is not logged, you can display your login view controller as modal so it will be over top of your tabBarController.
//something like that
-(void)load_login_view{
UIViewController * fb_login = [[FacebookLoginView alloc]init];
fb_login.title = #"fsf ss";
UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login];
[self.window.rootViewController presentViewController:fb_login_navigation animated:NO completion:nil];
}
->when you user is logged, dismiss the login controller. If needed, save user data for the next time
->do some work to update the selected controller inside your TabBarcontroller if needed.
Change your navigation flow
-> use UINavigationController with the login Controller ([[UINavigationController alloc] initWithRootViewController:fb_login]) as a rootController for your application
UIViewController * fb_login = [[FacebookLoginView alloc]init];
fb_login.title = #"fsf ss";
UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login];
self.window.rootViewController = fb_login_navigation;
-> when you user is logged, push to your TabBarcontroller. If needed, save user data for the next time
//inside fb_login controller ( you can optimize the code, it's just a quick example)
UIViewController * secondpage = [[SecondViewController alloc]init];
secondpage.title = #"second";
UINavigationController * secondpage_navigation = [[UINavigationController alloc] initWithRootViewController:secondpage];
[secondpage_navigation.tabBarItem setImage:[UIImage imageNamed:#"eventi.png"]];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[secondpage_navigation];
[self.navigationController pushViewController:tabBarController animated:YES];
->To avoid the double navigationBar (fb_login_navigation / secondpage_navigation), you can hide the navigation of fb_login_navigation when needed.
-> the next time, if the user is logged, you can fire the code above just after loading the login controller instead of waiting that the user enters his credentials.
Hope it helps.

Related

App freezes after opening it from an alertView received from a push notification

I have embedded APNS to my app and I navigate to a screen where I have details of the notification. The problem is, when clicked on the view button in the alert view, the app navigates to the .xib file and freezes.
What can I do to workaround this?
Heres the code used to open the viewController xib:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:#"RearTableViewController" bundle:nil];
DetailsViewController *detailsViewController = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
detailsViewController.messageID = [[[NSUserDefaults standardUserDefaults] objectForKey:#"messageId"] intValue];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:detailsViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
self.window.rootViewController = mainRevealController;
This may Help you.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
SplashVC *rootVC = [[SplashVC alloc]initWithNibName:#"SplashVC" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:rootVC];
[navigation setNavigationBarHidden:YES];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
This is my code when i receive push and show alert. If alerts one of the button pressed then this will present my view controller.
LocationViewController *locationVC = [storyboard instantiateViewControllerWithIdentifier:#"LocationVC"];
locationVC.latitude = fLat;
locationVC.longitude = fLong;
[self.navController presentViewController:locationVC animated:YES completion:nil];

how to add tab bar controller from the second view controller [duplicate]

This question already has an answer here:
Showing login view controller before main tab bar controller
(1 answer)
Closed 9 years ago.
Im beginner to IOS app development learning.
I have a login screen as my first view controller and i need the second view controller to be a tab bar view controller .with 4 different tabs and i have 4 different XIB's for them.
some one help me to go ahead.
Best way you can do is Present the login screen modally when the app starts from your tab bar controller first screen, add code for presenting login screen in viewWillAppear and after login dismiss the screen. You can create TabBarController in appDelegate like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController tabBarController=[[UITabBarController alloc] init];
FirstViewController *firstVC = [[UIViewController alloc] initWithNibName:#"FirstVC" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController: firstVC];
SecondViewController *secondVC = [[UIViewController alloc] initWithNibName:#"secondVC" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];
tabBarController.viewControllers = [NSArray arrayWithObjects: firstNavController, secondNavController, nil];
tabBarController.selectedIndex=0;
tabBarController.delegate = self;
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:#"Movies" image:[UIImage imageNamed:#"MoviesTAB.png"] tag:1];
[firstVC setTabBarItem:item1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:#"Music" image:[UIImage imageNamed:#"musicTAB.png"] tag:2];
[seconfVC setTabBarItem:item2];
tabController.tabBar.translucent = NO;
tabController.tabBar.barStyle = UIBarStyleBlack;
tabBarController.tintColor = [UIColor whiteColor];
self.window.rootViewController = tabController;
return YES;
}
Best way is use storyboard and there just have one initial UIViewController and from that make segue to UITabBarViewController.
http://youtu.be/a_DCTSTv1Mw
If you want to make it through xib make a UITabBarViewController and add viewControllers to the array of object of that UITabBarViewController's object.
Sample code :
NSMutableArray *arrViewControllers = [[NSMutableArray alloc] init];
UIViewController *tabController;
UIImage *tabImage ;
NSString *tabTitle;
for (int i= 0; i < 3; i++) {
switch (i) {
case 0:
tabController = [[ViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon1.png"];
tabTitle = #"Text";
break;
case 1:
tabController = [[ImageDemoViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon2.png"];
tabTitle = #"Image";
break;
case 2:
tabController = [[TableDemoViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon3.png"];
tabTitle = #"Table";
break;
}
// set the image and title using some properties of UIViewController
tabController.tabBarItem.image = tabImage;
tabController.tabBarItem.title = tabTitle;
//add objects to array
[arrViewControllers addObject:tabController];
[tabController release];
}
_baseController = [[UITabBarController alloc] init];
_baseController.viewControllers = arrViewControllers;
[arrViewControllers release];
go to your appDelegate
1.create a viewController for login screen.
LoginViewController *viewController1 = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
2.create a navigationController with root view your login ViewController.
UINavigationController *nVC = [[UINavigationController alloc] initWithRootViewController:viewController1];
3.make navigationController to root view of window.
self.window.rootViewController = self.nVC;
[self.window makeKeyAndVisible];
Now go to Touch-Up-Inside method of login button in LoginViewController.
1.After validation of password and userId initialise your viewControllers for tabbar and TabbarViewController.
UiViewController ...*yourViewControllers,..,
UITabBarController *YourtabBarController = [[UITabBarController alloc] init];
2.Now add these viewControllers to your tabbarController.
YourtabBarController.viewControllers = #[ YourViewController1,YourViewController2,YourViewController3,......];
3.Finally push this tabbarController to navigationControllere.
[self.navigationController pushViewController:YourtabBarController animated:NO];

TabBarController and NavigationController

I am making an application but I'm still a beginner and I'm trying to get used to the RootViewController and how it should be set.
At the beginning my application launches, I want there to be a View which is not in my tabBarController (which is set to be my rootViewController).
What I am trying to ask is, Can I have another view which is outside my UITabBarController launch first without it being in the tabBarController's items list?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FacebookFeedViewController *facebookClass = [[FacebookFeedViewController alloc] initWithNibName:#"FacebookFeedViewController" bundle:nil];
TwitterFeedViewController *twitterClass = [[TwitterFeedViewController alloc] initWithNibName:#"TwitterFeedViewController" bundle:nil];
LinkedInFeedViewController *linkClass = [[LinkedInFeedViewController alloc] initWithNibName:#"LinkedInFeedViewController" bundle:nil];
FTLFullFeedViewController *masterClass = [[FTLFullFeedViewController alloc] initWithNibName:#"FTLFullFeedViewController" bundle:nil];
/// tab button title
facebookClass.title = #"Facebook";
twitterClass.title = #"Twitter";
linkClass.title=#"LinkedIn";
masterClass.title=#"FTL";
// tab button Images
facebookClass.tabBarItem.image = [UIImage imageNamed:#"facebook_32"];
twitterClass.tabBarItem.image = [UIImage imageNamed:#"twitter_32"];
WelcomeViewController *welcomeClass= [[WelcomeViewController alloc] initWithNibName:#"WelcomeViewController" bundle:nil];
navController = [[ UINavigationController alloc] initWithRootViewController:welcomeClass];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:facebookClass];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:twitterClass];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:linkClass];
UINavigationController *navController5 = [[UINavigationController alloc] initWithRootViewController:masterClass];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController5,navController2,navController3,navController4,nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I know you already selected an answer but all that's doing is pushing a UITabBar view on top of an existing view, not creating a new UITabBarController view. Based on our brief conversation (latest XCode, no StoryBoards, using XIBs) you're going to want to create a xib as a UITabBarController then push it into view...
View *view = [[View alloc] initWithNibName:#"myUITabBarXIB" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: view animated:YES];
This will present your XIB file but not on top of the existing view controller when the desired action takes place.
yes! ofcourse you do.
[self.view addsubview:yourTabbar.view];
Hope this will help you.

How to Show LoginViewController over SplitViewController?

I am working on application for iPad which have CustomTabBar (3 Tabs), Navigation Bar and SplitView Controller.
Follow of application screens:
1-Login Screen (Present over SplitView) >> Forgot password (Push on login navigation)
2- Forget password if pushed on login navigation then it will be poped and then login will be dismissed on successful login.
3- On Successful Login, SplitView is shown.
How I code in AppDelegate:
self.detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:self.detailViewController] autorelease];
customTabBarCont = [[CustomTabBarController alloc] init];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = self.detailViewController;
NSArray *viewControllers = [[[NSArray alloc] initWithObjects:customTabBarCont,detailNavigationController, nil] autorelease];
self.splitViewController.viewControllers = viewControllers;
self.detailViewController.splitViewController = self.splitViewController;
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
loginVC = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
UINavigationController *loginNavigationController = [[[UINavigationController alloc] initWithRootViewController:loginVC] autorelease];
[self.splitViewController presentViewController:loginNavigationController animated:NO completion:nil];
I have SettingViewController in which i have given the functionality of Sign-out.
It create issues when user Signout from Portrait and Login in LandscapeView
How i code for SignOut
self.loginVC = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
if ([app_delegate.detailViewController.masterPopoverController isPopoverVisible]) {
[app_delegate.detailViewController.masterPopoverController dismissPopoverAnimated:NO];
}
UINavigationController *loginNavigationController = [[[UINavigationController alloc] initWithRootViewController:self.loginVC] autorelease];
When we rotate again then everything goes well. but how to solve this issue. or where i am wrong.
You just have to add one method in your DetailViewController.m
- (BOOL)splitViewController:(UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
return NO;
}
The run you project and see what happens. Surly this will solve your problem

xCode 4.2 UITableView drilldown

I'm a newbie to the xCode world and I had a few questions regarding my application setup.
My application a list of Authors, click on author and get author detail plus book titles, and then click on the book title and get book information, but I'm unable to figure out the show detail part.
I have established a tab view controller that displays UIViewControllers in the window.
//create view controllers
UIViewController *vc1 = [[HomeViewController alloc] init];
UIViewController *vc2 = [[AuthorViewController alloc] init];
UIViewController *vc3 = [[BooksViewController alloc] init];
UIViewController *vc4 = [[GenreViewController alloc] init];
UIViewController *vc5 = [[UserViewController alloc] init];
//create instance of tab bar
self.tabBar = [[UITabBarController alloc] init];
//add views to tab bar
self.tabBar.viewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3, vc4, vc5, nil];
self.window.rootViewController = self.tabBar;
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
[_window addSubview:_tabBar.view];
[self.window makeKeyAndVisible];
return YES;
This works perfectly. My first view "AuthorViewContoller" is a table and I can display data, however I can NOT get the detailController to show.
My AuthorViewController viewDidLoad method
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.author= [[NSArray alloc] initWithObjects:#"One", #"two", nil];
self.detailController = [[AuthorDetailController alloc] init];
and my methoddidSelectRowAtIndexPath:
if(indexPath.row == 0)
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
AuthorDetailController *dc = [[AuthorDetailController alloc] initWithNibName:#"AuthorDetailController" bundle:nil];
dc.title = [author objectAtIndex:indexPath.row];
[self.navigationController pushViewController:dc animated:YES];
}else{
[self.navigationController pushViewController:detailController animated:YES];
}
I'm declaring detailController in my AuthorViewController.h file.
#property (nonatomic, retain) IBOutlet AuthorDetailController *detailController;
You have to actually create a UINavigationController, and have it be part of your controller hierarchy, before you can use pushViewController:animated:. You should really try setting this up in a NIB, instead of code, but in your code you can try this in place of your current vc2 initialization:
UIViewController *vc2 = [[UINavigationController alloc] initWithRootViewController:[[AuthorViewController alloc] init]];

Resources