Adding a registration page before the tabViewController in IOS - ios

I have a UITabBarController that is working good.
Now before I open the tabController, I want to check if the user is registered, if not I want to open a registration page (RegistrationController) and then go back to my tabView.
How can I do this, since the TabBarController can only be the first page.
Thank you

u can have a viewController(VC1) pushing another viewController (VC2) and in viewDidLoad of VC2 u can add ur tabbar programmatically.
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.backgroundColor = [UIColor clearColor];
VC3 *object1 = [[VC3 alloc] initWithNibName:#"VC3" bundle:nil];
VC4 *object2 = [[VC4 alloc] initWithNibName:#"VC4" bundle:nil];
tabBarController.viewControllers = [NSArray arrayWithObjects:object1, object2, nil];
tabBarController.delegate = self;
[[tabBarController.viewControllers objectAtIndex:0] setTitle:#"title"];
[[tabBarController.viewControllers objectAtIndex:1] setTitle:#"title"];
[self.view addSubview:tabBarController.view];
[object1 release];
[object2 release];
also u can do this
in the viewDidLoad of the tabBarController (default view), u can check a variable, if its 0 (i.e. user is not registered), then u can presentModalViewController with a registration form.
hope it helps. happy coding :)

You can add an overlay, over the table view controller (another view which will make the table view not visible, since it will be behind the view you're adding). On succcessfull login / registration, you remove the overlay view.

Related

How to display navigation controller (set of view controllers) such as login or register before adding UITabBarController

I had an application in which I need to have a login or register system before the tab bar controller is added to the window, such as in Instagram.
I have added 5 navigation controllers (with view controller as its root) to the UITabBarController and then set it as the root of the window. Before that, I need to have another UINavigationController for the login system.
If I add that, how do I remove it before adding tab?
Another problem is that I also have to handle logging out, so I need to come back to it.
Can anybody help me with me how to do this?
I suggest to you loading Loginview From Delegate window as we did Normally. and from Logged Success its button click you set TabbarController like this:-
UIViewController *viewControllerPostalCode2 = [[cntrServices alloc] initWithNibName:#"cntrServices" bundle:nil];
UIViewController *viewControllerPostalCode3 = [[cntrInquiryViewController alloc] initWithNibName:#"cntrInquiryViewController" bundle:nil];
UINavigationController *navPostage1 = [[UINavigationController alloc] initWithRootViewController:viewControllerPostalCode2];
UINavigationController *navPostage2 = [[UINavigationController alloc] initWithRootViewController:viewControllerPostalCode3];
//
navPostage1.navigationBar.tintColor =DARK_BACKGROUNDNavigation;
navPostage2.navigationBar.tintColor =DARK_BACKGROUNDNavigation;
//
self.tabBarForServicesController = [[UITabBarController alloc] init];
self.tabBarForServicesController.delegate=self;
self.tabBarForServicesController.viewControllers = [NSArray arrayWithObjects:navPostage1,navPostage2,nil];
[self.navigationController pushViewController:self.tabBarForServicesController animated:YES];
I Done this type of Task using this method and at the Logged Out just poptoRootviewController work back to the Logged in Screen.
I have done this like adding my tabbarcontroller as rootViewController to UIWindow and in applicationbecomeactive delegate i present a controller with navigation controller like when required and simply dismiss the controller when authentication done
UIViewController *topViewController = [self.navController topViewController];
if (![topViewController isKindOfClass:[LGLoginViewController class]]) {
[self.navController popToRootViewControllerAnimated:YES];
self.navController = nil;
LGLoginViewController* loginView = [[LGLoginViewController alloc] initWithNibName:#"LGLoginViewController"bundle:nil];
if (!self.navController) {
self.navController = [[UINavigationController alloc] initWithRootViewController:loginView];
} else {
[self.navController initWithRootViewController:loginView];
}
self.navController.delegate = self;
[self.window.rootViewController presentModalViewController:self.navController animated:NO];
}

Dismiss TabBarController From one of it's UINavigationControllers and return to the Controller from where the TabBarController was presented

I am presenting a UITabBarController from another ViewController (HomeViewController). The TabBarController in turn contains UINavigationControllers. However, when from one of the navigation controllers, the user presses the home button, he is required to go to the original ViewController from where the TabBarController was presented.
**tabBarController is not the rootViewController of my window.
Here's my code.
In AppDelegate, I am creating and configuring my TabBarController.
self.custCareVC = [[CustomerCareViewController alloc] initWithNibName:#"CustomerCareViewController_iPhone" bundle:NULL];
self.POController = [[PurchaeOrderViewController alloc] initWithNibName:#"PurchaeOrderViewController_iPhone" bundle:NULL];
self.accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:#"AccountsAndContactsViewController_iPhone" bundle:NULL];
self.customerCareNavController = [[UINavigationController alloc] initWithRootViewController:self.custCareVC];
self.customerCareNavController.title = #"Customer Service";
self.purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:self.POController];
self.purchaseOrderNavController.title = #"PO";
self.accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:self.accAndContactsController];
self.accAndContactsNavController.title = #"Accounts And Contacts";
self.tabBarController = [[UITabBarController alloc] init];
//self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"bluehead.png"];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.customerCareNavController, self.accAndContactsNavController, self.purchaseOrderNavController, nil];
In my HomePageViewController, i am presenting it in the following way (on click of a button):
AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
appDel.tabBarController.delegate = self;
[self presentViewController:appDel.tabBarController animated:YES completion:NULL];
Now i need to dismiss my tabBarController after a user presses a Button on any of the navigation controllers (present in the tabBarController) and show the HomeViewController again..!!
You need to create a function in your target controller (which has the power to dismiss the tabBarController) and call that function from your topmost(current) controller/ controller the user is currently interacting with. To achieve the above, you need to first get the tabBarController object from the current controller using parent view controller. Then get the parent view/ root view controller of that controller and performSelector (function) which you created in the first controller.
Be sure to check doesRespondToSelector before you call performSelectorso as to avoid any nasty crashes.
Another way, though pretty hackie is to store a weak reference of the first controller in the AppDelegate and access the same from you current controller.

Can't get rid of "Splitview controller is expected to have a view controller at index 0 before it's used" error in iOS6

I'm trying to convert my app to universal for iPad support and whatever I do I can't get rid of the "Splitview controller is expected to have a view controller at index 0 before it's used!" error right after the app stars.
I'm using iOS6 as target, XCode 4.6.3. Tried all the things that I could find on this website and Google, didn't help me at all.
I want to add a TabBar controller as a Main one (left one in the Split Controller) and some other controllers as a detail one.
Here is my current code in AppDelegate.m:
tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:[NSArray arrayWithObjects:navAddVC, nav, svcNav, stvcNav, nil]];
FirstDetailViewController *fdvc = [[FirstDetailViewController alloc];
initWithNibName:#"FirstDetailViewController" bundle:nil];
UINavigationController *fdvcNav = [[UINavigationController alloc] initWithRootViewController:fdvc];
viewControllers = [[NSArray alloc] initWithObjects:tabController, fdvcNav, nil];
UISplitViewController *splitvc = [[UISplitViewController alloc] initWithNibName:nil bundle:nil];
[[splitvc view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"splitViewControllerBG"]]];
[splitvc setViewControllers:viewControllers];
[splitvc setDelegate:fdvc];
[[self window] setRootViewController:splitvc];
[[self window] makeKeyAndVisible];
I'd appreciate any help, thanks.
Thanks to #Wain I solved it.
The thing was that by setting up a background image to my split vc I was loading its view.
So the solution is to set viewControllers array before the setting background color.

load page with pushViewController on tabbar

I have UIViewController with tabbar botton, and navigation bar and navigation item,
when I press on my button in navigation Item I want to load a view, I don't know how to load this view on tabbar,
would you please help me,thanks in advance!
-(IBAction) infoPage:(id)sender
{
InfoCtrol *i = [[InfoCtrol alloc] initWithNibName:#"InfoCtrol" bundle:nil];
[self.navigationController pushViewController:i animated:YES];
}
This will load the InfoCtrol controller and set the Touch UpInside Event in xib to the infoPage method
Do you mean you want to hide the tab bar when you push new controller in navigation?
If true. There is a property hidesBottomBarWhenPushed in the UIViewController class.
// Instead of adding ViewController to TabbarController, add NavigationControllers.
// Eg.
UINavigationController *NavController = [[UINavigationController alloc] initWithRootViewController:_viewCtrl1];
[watchListNavController.navigationBar setTintColor:[UIColor blackColor]];
_tabC = [[UITabBarController alloc] init];
_tabCt.viewControllers = [NSArray arrayWithObjects:NavController,_viewCtrl2,_viewCtrl3, nil];
// Now you can use Push and Pop In your _viewCtrl1.
// Do same with all the viewController

Can I change the first screen of tab item programatically?

Can I change the first screen of a tab item programatically?
For example,
When user is in Tab A, upon tapping a button there, user will be
navigated to Tab C with Screen 1 However, when user is in Tab C, upon
tapping a button here, user will be navigated to Tab C with Screen 2.
Therefore, both screen 1 and 2 will be the first screen of Tab C
depend on where the user comes from.
Can I achieve something like that?
Thanks!
Based on this post How to replace a navigation root controller by tab bar controller in existing iphone app , can change the view controllers by this code:
NSMutableArray * viewControllers = [[NSMutableArray alloc]init];
FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];
SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];

Resources