iPhone changing the rootviewcontroller dynamically? - iphone

I will use UINAvigationController in my app, but noticed that my rootview should be either a tableview or a uiview depending on content I received. as you know It comes with a tableview by default. how can I push my first view dynmacally here ?

U can do like this in application:didFinishLaunchingWith.... in app delegate.
For this, u need to create the application with window based application template.
DetailViewController *detailView = [[DetailViewController alloc] initWithNibnam..];
UINavigationController *uiNavController = [[UINavigationController alloc] initWithRootViewController:detailView];
self.window.rootViewController = uiNavController;
[detailView release];
[uiNavController release];

Related

How to reposition code previously placed in Appdelegate.m

I think the title of the question may be misleading as I'm not quite sure how to word this in a line.
I'm trying to implement a reveal controller (like those seen in the Facebook app), and I'm using a sweet pre-made solution SWRevealViewController which can be found here.
In one of the most simple examples the author provides (Example/project 2), in the Appdelegate.m file the reveal controller stuff is established:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
self.viewController = mainRevealController;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Where viewcontroller is defined in the appdelegate.h file by
#property (strong, nonatomic) SWRevealViewController *viewController;
So this displays the reveal controller as the root view controller. For my app, my root view controller is different and I only start using the reveal controller later in the app. My root view controller is the login screen, and then the proceeding view is where I want to implement this.
I guess my questions are:
Firstly, is it correct to put the login screen as the root view controller? Should I be using some sort of modal view to pop this up then get rid of it?
How and where would I go about putting the stuff previously found in the delegate files? Or do they remain there but are not assigned to the root view controller?
I feel really in the dark about this, so forgive me if it seems completely trivial.
Thanks!
I have thought about this problem recently. In fact all other third party implementations I found all have this setup.
My recommendation is to change the root controller to the reveal controller and build everything up from there. You can disable reveal for your original root, login or any other controller. I did it once and it was not as painful as anticipated.
I am late to the party, the behavior you want is easy to implement, just think about it as a normal navigation stack. Let's take the example 2 which you were following along the way (you don't need to move the code out of the delegate). Instead of setting the front view controller as the root of the front navigation controller, you should set the login view controller as the root of the front navigation controller.
Here is the example before:
FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
And here is the example after setting the login view controller:
LoginViewController *loginVC =[[LoginViewController alloc]init];//instead of frontViewController
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:loginVC];//instead of frontViewController
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
Don't forget to create the LoginViewController or whatever you choose to name with its nib file and to import it.
In LoginViewController, you need to implement the action code to move to the frontviewcontroller:
FrontViewController *frontViewController = [[FrontViewController alloc] init];
[self.navigationController pushViewController:frontViewController animated:YES];
Et voila.

Moving to next view in popover displaying UITableView

I have created an application for iPhone interface which displays a UITableView as its rootviewcontroller. When we select any of its row, it opens the corresponding detailViewController, we select the value from there and it is displayed in the cells of UITableView in masterViewController. This application was running perfectly fine in iPhone simulator as desired.
Now I want to incorporate this application to an iPad application. For that purpose, I have created a UIPopOver and assigned the masterViewController to the popover. Now the problem is, UITableView is initially shown in the popover. But when we select any row, next view doesn't appear in popover as it appeared when application was running solely for iPhone. How should I make it work so that I can import the application with original functionality in UIPopOver?
I think you are pushing DetailViewController from your masterViewController.But your masterviewController should implement NavigationController, I mean while displaying masterViewController(your tableviewcontroller) in popover you should do as follows:
MasterViewController *theMasterViewController = [[MasterViewController alloc] init];
UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController:theMasterViewController];
[theMasterViewController release];
UIPopoverController *popOverController = [[UIPopoverController alloc] initWithContentViewController:navCont];
popOverController.popoverContentSize = CGSizeMake(400, 400);
[popOverController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
and when user selects any row, then in didSelectRowAtIndexPath do as follows:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Hope this helps!

Push notification in view based app?

I created a view based app. In a view Controller class I created a tab bar Dynamically. The App is running fine, but I am having a problem with handling a push-notification. While Push-notification sent means I received the push alert, I want to know how to show selected index 3 of my Tab bar.
in the view based application after 2 class i create this tabbar dynamically.
tabbar1 = [[UITabBarController alloc] init];
tab_obj1 = [[First alloc] initWithNibName:#"First" bundle:nil];
UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController: tab_obj1] autorelease];
tabItem1.title=#"First";
tabItem1.tabBarItem.image=[UIImage imageNamed:#"FirstIcon.png"];
tab_obj2 = [[Second alloc] initWithNibName:#"Second" bundle:nil];
UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController: tab_obj2] autorelease];
tabItem2.title=#"Second";
tabItem2.tabBarItem.image=[UIImage imageNamed:#"SecondSelc.png"];
tab_obj3 = [[Third alloc] initWithNibName:#"Third" bundle:nil];
UINavigationController *tabItem3 = [[[UINavigationController alloc] initWithRootViewController: tab_obj3] autorelease];
tabItem3.title=#"Third";
tabItem3.tabBarItem.image=[UIImage imageNamed:#"ThirdIcon.png"];
tab_obj4 = [[Fourth alloc] initWithNibName:#"Fourth" bundle:nil];
Write your code to select tabbar index in the below method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Notification code here
}
Above Method calls everytime notification comes, so you can write your code here for the selection of tabbar index.
Your question has nothing to do with Push Notification...
To show any given tab of your TabBarController, you can do something like this:
tabBarController.selectedIndex = 3;
where tabBarController is a pointer to your application's tab bar controller object.
There are special considerations for changing selectedIndex to a value that represents the More controller. Check the documentation for UITabBarController and the selectedIndex property for the details.
Hi Developers, Thanks for responding me.I will show that badge value inside the tabBar tab.
I create tabBar controls again in didReceiveRemoteNotification method and in non-active state app from this tabbarcontroller_obj.tabBarItem.badgeValue=#"3" Like this I handle the notification badge value inside the application.

Right design pattern for tabbed navigation views?

I've been stuck trying to puzzle this out for a couple days now, and I'll admit I need help.
The root view controller of my application is a tab bar controller. I want to have each tab bar a different navigation controller. These navigation controllers have completely different behavior.
So how do I set this up in terms of classes? Per Apple's documentation, I'm not supposed to subclass UINavigationViewController. So where do I put the code that drives each of these navigation controllers? Does it all get thrown in App Delegate? That would create an impossible mess.
This app should run on iOS 4.0 or later. (Realistically, I can probably require iOS 4.2.)
This is taken from one of my applications. As you say, you are not supposed to subclass UINavigationController, instead you use them as they are and you add viewcontroller on the UINavigationController's. Then after setting the root viewcontroller in each UINavigationController, you add the UINavigationController to the UITabBarController (phew!).
So each tab will "point" to a UINavigationController which has a regular viewcontroller as root viewcontroller, and it is the root viewcontroller (the one you add) that will be shown when a tab is pressed with a (optional) navigationbar at top.
UITabBarController *tvc = [[UITabBarController alloc] init];
self.tabBarController = tvc;
[tvc release];
// Instantiates three view-controllers which will be attached to the tabbar.
// Each view-controller is attached as rootviewcontroller in a navigationcontroller.
MainScreenViewController *vc1 = [[MainScreenViewController alloc] init];
PracticalMainViewController *vc2 = [[PracticalMainViewController alloc] init];
ExerciseViewController *vc3 = [[ExerciseViewController alloc] init];
UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *nvc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc1 release];
[vc2 release];
[vc3 release];
nvc1.navigationBar.barStyle = UIBarStyleBlack;
nvc2.navigationBar.barStyle = UIBarStyleBlack;
nvc3.navigationBar.barStyle = UIBarStyleBlack;
NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nvc3, nil];
[nvc1 release];
[nvc2 release];
[nvc3 release];
self.tabBarController.viewControllers = controllers;
[controllers release];
This is how I go from one viewcontroller to another one (this is done by tapping a cell in a tableview but as you see the pushViewController method can be used wherever you want).
(this is taken from another part of the app)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.detailedAnswerViewController == nil) {
TestAnsweredViewController *vc = [[TestAnsweredViewController alloc] init];
self.detailedAnswerViewController = vc;
[vc release];
}
[self.navigationController pushViewController:self.detailedAnswerViewController animated:YES];
}
The self.navigationcontroller property is of course set on each viewcontroller which are pushed on the UINavigationController hierachy.

iphone programming objective-c : viewDidLoad() execution

my application have a tabbarcontroller with 4 view Controllers.
Its called here :
self.window.rootViewController = tabBarController;
The view controller that appear first in the tabbar is called "Home"
I want when opening the app to load the viewcontroller and not just the tabbar. It is possible? I want the ViewDidLoad() method from my Home view controller to be called. Thanks
If your application is based on a TabBarController, you want to load the viewControllers into your TabBarController and then add the TabBarControllers view to the window. For example:
FirstViewController *fvc = [[FirstViewController alloc] init];
SecondViewController *svc = [[SecondViewController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:fvc,svc,nil];
[window addSubview:tabBarController.view];
[fvc release];
[svc release];
where tabBarController is an instance variable and property. The first tab to display when your app launches will be the first one you load into the array. In this case it is fvc.
Hope this helps.
Just go as usual load the first viewController (use it as Home page )and handle the tabbar hidden property (where you want to show or hide it).