i am using Following code in appdelegate.m file..but it did not work..?
OthersController *mm_OthersController = [[OthersController alloc] init];
[mm_OthersController tScreen];
[mm_OthersController release];
when i put break point, it goes to the function tScreen correctly....but i can get output..?if i call the method "tScreen" from view willappear of OthersController, it works fine....
the method in OthersController.m file
-(void)tScreen
{
[self.navigationController setToolbarHidden: NO animated: NO];
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
}
any help pls......?
You should check whether you are doing this after adding the navigation controller to your window or before it.
Follow it like this:
[window addSubview:[navigationController view]];
OthersController *mm_OthersController = [[OthersController alloc] init];
[mm_OthersController tScreen];
[mm_OthersController release];
[window makeKeyAndVisible];
Hope this helps!
Related
In delegate class I wrote the code as follows
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
[self generateFirstScreen];
[self removeFirstScreen]; // On login check implement this method or u can directly write the snippet here as well.
[self prepareControllersOnTabs]; //your tab controller code function
[self.window makeKeyAndVisible];
return YES;
}
-(void) removeFirstScreen
{
[firstScreen removeFromSuperView];
self.window.rootViewController = self.tabBarController;
[firstScreen release];
}
-(void) generateFirstScreen
{
FirstScreen *firstScreen = [[FirstScreen alloc]init];
[self.navigationController pushViewController:firstScreen animated:YES];
[firstScreen release];
}
but generateFirstScreen works fine but removeFirstScreen gives an exception Please help me.
Specify exception...
Without addSubview how can you remove it from super. Do you want to use popViewController.?
Again you are allocating firstScreen only once & releasing it twice..!
Don't remove a screen if you're not sure it's added to a view, otherwise you get a crash.. you can specify a tag to this view and check the subviews of the main view to check whether your view is in there somewhere..
your generateFirstScreen method Change like below
FirstScreen *firstScreen = [[FirstScreen alloc]initWithNibName:#"FirstScreen" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.objLogin];
// Add the navigation controller's view to the window and display.
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
//call this metod when ever u want tabbar
-(void)tabBarControllerView
{ [self.navigationController.view removeFromSuperview];
[self.navigationController.view setHidden:YES] ;
self.tabBarController.selectedIndex = 0;
self.tabBarController.view.hidden=NO;
[window addSubview:self.tabBarController.view];
}
i'm playing around with the great library ZUUIRevealController. However, I can't program it so the user are able to tap a cell in the rearcontroller. The rearcontroller should then go away and display a new viewcontroller in the front view.
I've setup my project like this:
VGViewController *frontViewController;
RevealController *rearViewController;
frontViewController = [[VGViewController alloc] initWithNibName:#"VGViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
rearViewController = [[RevealController alloc] initWithNibName:#"RevealController" bundle:nil];
ZUUIRevealController *revealController = [[ZUUIRevealController alloc] initWithFrontViewController:self.navigationController rearViewController:rearViewController];
[frontViewController release];
[rearViewController release];
self.window.rootViewController = revealController;
[revealController release];
[self.window makeKeyAndVisible];
return YES;
I hope someone can help me! :D
glad you found a liking in the library.
Your project seems to be setup correctly if I'm not missing anything, although logically I'm not able to follow how the rearViewController <=> RevealController but that's okay I guess.
To answer your question:
In order to display a different frontViewController by, say tapping on a cell in the rearViewController you need to trigger this piece of code in the appropriate method (say: tableView:didSelelctRowAtIndexPath:)
// RearViewController.m file in some method:
// - Let's grab a reference to the revealController first:
ZUUIRevealController *revealController = [self.parentViewController isKindOfClass:[ZUUIRevealController class]] ? (ZUUIRevealController *)self.parentViewController : nil;
// Check if we're not attempting to swap the current FrontViewController for exactly the same controller over again...
if (![revealController.frontViewController isKindOfClass:[NewFrontViewController class]])
{
NewFrontViewController *newFrontViewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
newFrontViewController = [[NewFrontViewController alloc] initWithNibName:#"NewFrontViewController_iPhone" bundle:nil];
}
else
{
newFrontViewController = [[NewFrontViewController alloc] initWithNibName:#"NewFrontViewController_iPad" bundle:nil];
}
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newFrontViewController];
[newFrontViewController release];
[revealController setFrontViewController:navigationController animated:NO];
[navigationController release];
}
What this piece of code does is, it grabs a reference to the rearViewControllers parent (which should be the revealController), and assigns a new frontViewController instance to it by calling [revealController setFrontViewController:navigationController animated:NO];
Hope this solves your problem :-)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
UINavigationController *nav_obj = [[UINavigationController alloc] initWithRootViewController:overviewViewController ];
[self.viewController presentModalViewController:nav_obj animated:YES];
[overviewViewController release];
[self.window makeKeyAndVisible];
return YES;
}
This code shows the blue bar of navigation controller, but no buttons on it.It seems like to be that the UINavigationController allocated as empty.
Who knows what problems is?
UPD:Archive http://www.mediafire.com/?lbjjvl6fcue2q18
Please help me, I'm new in objective-c
You need to create the button for it, for example:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:launcherView action:#selector(endEditing)];
self.navigationItem.leftBarButtonItem = doneButton;
[doneButton release];
The correct way to use a UINavigationController is to push view controllers on to it. That way they will be stacked and the navigation bar will be populated with a back button when it is case (i.e., when you can actually go back to a previous controller). You control the label that appears in the "back" button by defining the title of the controllers you push.
The technique shown in another answer (setting explicitly the button) is useful with defining the right button, if you ever need one.
You could try with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
UINavigationController* navigation = [[UINavigationController alloc] init];
[navigation pushViewController:overviewViewController animated:NO];
[overviewViewController release];
[window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
return YES;
}
Instead of doing:
UINavigationController* navigation = [[UINavigationController alloc] init];
[navigation pushViewController:overviewViewController animated:NO];
you could also use initWithRootController, but to display the general case of how you push a view controller I preferred this one.
Notice that since you are pushing just a root controller, you should see no back button at the moment, but if you push a second view controller, then it will appear.
EDIT: I gave a look at your project. Summary of what you should try and do:
objects you need in your NIB: File's Owner (UIApplication), First Responder, FBFun App Delegate (iVkAppDelegate), Window (UIWindow); remove the rest;
File's owner delegate outlet is FBFun App Delegate;
FBFun App Delegate window outlet is Window.
With this simple setup (more or less what you have), use this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController* navigation = [[UINavigationController alloc] init];
//-- MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
iVkViewController *overviewViewController = [[iVkViewController alloc] init];
overviewViewController.title = #"First";
[navigation pushViewController:overviewViewController animated:NO];
iVkViewController *overviewViewController2 = [[iVkViewController alloc] init];
overviewViewController2.title = #"Second";
[navigation pushViewController:overviewViewController2 animated:NO];
[overviewViewController release];
[window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
return YES;
}
In the code above, as you notice, I instantiated twice your iVkViewController just to have a second controller to push onto the navigator.
Please, delete your existing app from the simulator, and the run this in order to see that the navigation bar is correctly created and you can go back from the second controller to the first one.
I removed usage of MainPageDialog, because the MainPage nib has many problems.
But I hope this skeleton is sufficient for you to go forward with your development.
You had missed the line as you are not adding view to window.Add this line in your code
[window addSubview:nav_obj.view];
I am having a problem with the following code:
MyViewController *aController = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
self.myController = aController;
myController.title = #"List";
[aController release];
UINavigationController *bController = [[UINavigationController alloc] initWithRootViewController:myController];
self.rootNavController = bController;
[bController release];
[self.view addSubview:rootNavController.view];
When I run my program I get the problem where my view for myController is repeated along the y-axis all the way until the bottom of the screen. If I add myController.view to the root view it works ok. I only have the problem when I add myController as the rootViewController of my navigation controller.
Thanks in advance for any help!
The default navigation controller project template defines -applicationDidFinishLaunching this way:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
I realize you're instantiating your nav controller with alloc init rather than getting it from the XIB, however, it seems you ought to be adding it to the window's view tree.
Where is the code you are showing being called from?
The problem was that I did not specify the frame. Without specifying a frame using CGRectMake the view controller was just filling the entire space.
The line I needed was something like this:
rootNavController.view.frame = CGRectMake(0, 0, 320, 431);
Try this:
MyViewController *aController = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
self.myController = aController;
[aController release];
UINavigationController *bController = [[UINavigationController alloc] initWithRootViewController:myController];
self.rootNavController = bController;
[bController release];
[window addSubview:rootNavController.view];//<--What are you adding the navigationController to??? Another ViewController? TabController? or Window?
Then in the -(void)viewDidLoad method of MyViewController you can put
self.navigationItem.title = #"List";
i have coded in appdelegate.m as following to change from currentview to UItable viewcontroller?but i am getting error,tab is a uitableview controller
tab = [interviewViewController alloc];
[viewController.view removeFromSuperview];
[viewController.view addSubview:tab];
[window addSubview:viewController.view];
YOu never initialize tab, and you addit to viewController. I'm not really sure what you're trying to do.
Do this:
tab = [[interviewViewController alloc] init];
[viewController.view removeFromSuperview];
[window addSubview:tab.vew];