I am having a problem with title and UINavigationController. I am using the following code at UIViewControllerCurrent and when I get back from NextViewController, the title of the NavBar is still "Previous" ..Can anyone kindly help me out with this problem ? Thanks.
[self setTitle:#"Previous"];
NextViewController *controller = [[NextViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
- (void)viewWillAppear:(BOOL)animated; {
[self setTitle:#"Real Title"];
[super viewWillAppear:animated]; }
I would try to exchange the two lines
[self setTitle:#"Real Title"];
[super viewWillAppear:animated];
so that you get
[super viewDidAppear:animated];
[self setTitle:#"Real Title"];
and I would put these into viewDidAppear.
Try using UINavigationController delegate methods below.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
Use one of the delegate method to change title.
If dasdoms solution is not working the try the following.
In the NextViewController just before poping out run this code.
for (int i =0; i < [[self.navigationController viewControllers] count]; i++)
{
UIViewController *aController = [[self.navigationController viewControllers] objectAtIndex:i];
if ([aController isKindOfClass:[PreviousViewController class]])
{
PreviousViewController *aPreviousViewController = (PreviousViewController *)aController;
aPreviousViewController.title = #" Real Title";
}
}
Related
I have a view(HomeView) in which i open a popOver. The popoVer content View is (ListView) which contains a Table View.
Now, when i select the row, The HomeView will dismissed & open a new View(MapView).
Till now, It works fine. But my all views contain tabbar in xib. I don't have tab bar in ListView.
So, i just open MapView with present Modal View. But from that my navigation is not working.
My code is as following.
HomeView.m
//open popview with ListView
-(IBAction)btnTableMenu_TouchUpInside:(id)sender{
ListView *popUp=[[ListView alloc] initWithNibName:#"ListView" bundle:nil];
popView = [[UIPopoverController alloc]initWithContentViewController:popUp];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(300, 700)];
[popView presentPopoverFromRect:CGRectMake(150,25,20,50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
ListView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self];
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
[self presentModalViewController:mapVC animated:YES];
//[self.navigationController pushViewController:mapVC animated:YES];
}
How can i solve this??
you just do like this way:-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self];
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:mapVC];
navbar.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
[navbar setModalPresentationStyle:UIModalPresentationFormSheet];
[navbar setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navbar animated:YES];
}
in MapViewController.m file ViewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *CancleButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancel)];
self.navigationItem.leftBarButtonItem = CancleButton;
}
-(void)cancel
{
[self dismissModalViewControllerAnimated:YES];
}
Do you know the difference btw ..
[self presentModalViewController:controller animated:YES];
& [self.navigationController pushViewController:controller animated:YES];
\When you do presentModalViewController:controller you lost the last Navigation stack.You need to create different navigationController for presenting the View. Read this properly you will get Idea .
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
Try following these-
ListView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self userInfo:[NSDictionary dictionaryWithObject:#"map" forKey:#"selectedView"]];
}
HomeView.m
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissModal:) name:#"DismissModal" object:nil];
- (void) dismissModal:(NSNotification *)notification
{
[self dismissModalViewController:mapVC animated:NO];
if([[notification.userInfo valueForKey:#"selectedView"] isEqualToString:#"map"])
{
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mapVC];
[self presentModalViewController:navController animated:YES];
}
}
help me please. How can I show another view controller after dismissing the existing one? here is my code:
- (void)matchmakerViewControllerWasCancelled:
(GKMatchmakerViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
ViewController *Vc = [[ViewController alloc]init];
[self presentModalViewController:Vc animated:YES];
}
My code doesn't work. Help me please. If i wrote NSLog after dismissingModalViewController, it shows me that NSLog, but ViewController won't show. thanks
[self dismissModalViewControllerAnimated:YES]; has been deprecated. Try doing:
- (void)matchmakerViewControllerWasCancelled:
(GKMatchmakerViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:^{
ViewController *Vc = [[ViewController alloc]init];
[self presentViewController:Vc animated:YES completion:^{}];
}];
}
Simply check this
[self dismissModalViewControllerAnimated:NO];
Nextview *sec = [[Nextview alloc] initWithNibName:#"Nextview" bundle:nil];
[self presentModalViewController:sec animated:YES];
[sec release];
Hope this works.
I have 3 classes.
First controllor is the first controllor in tabbar. I am using presentModalViewController to present a login screen and a Home screen. I have a presentModalViewController in firstcontrollor which present the login screen and in Loginscreen viewdidload method I have presentModalViewController which present home screen. The home screen presentModalViewController is dismissed in homePage_Btn_Clicked and presentModalViewController is dismissed in login_Btn_Clicked. The problem I have is my home screen is never presented. Any help? I am new in iPhone development.
//First Controllor
FirstControllor.m
- (void)viewDidLoad
{
[super viewDidLoad];
Accounts_Login *lvc = [[Accounts_Login alloc]initWithNibName:#"Accounts_Login" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc animated:NO];
[lvc release];
}
//Login_view class
Login_view.m
- (void)viewDidLoad {
[super viewDidLoad];
Home_Screen *lvc1 = [[Home_Screen alloc]initWithNibName:#"Home_Screen" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc1 animated:NO];
[lvc1 release];
user_ID_TextField.text = [[NSUserDefaults standardUserDefaults] objectForKey:#"User ID"];
}
-(IBAction) login_Btn_Clicked{
if ([services authenticate:credential_Data]) {
[self dismissModalViewControllerAnimated:YES];
[credential_Data autorelease];
}
//HomePage class
HomePage.m
-(IBAction) homePage_Btn_Clicked:(id) sender{
UIButton *theButton = (UIButton *)sender;
int count;
switch (theButton.tag) {
case 101:
count++;
[self dismissModalViewControllerAnimated:YES];
break;
default:
break;
}
}
Move presentModalView from viewDidLoad to viewDidAppear.
Try this:
Home_Screen *lvc1 = [[Home_Screen alloc]initWithNibName:#"Home_Screen" bundle:[NSBundle mainBundle]];
[self.parentViewController presentModalViewController:lvc1 animated:NO];
[lvc1 release];
I have the following action that gets called when a button gets clicked. The log message gets printed yet, the view doesn't change. This function is in a UIViewController.
Any ideas what I am doing wrong? Why isn't the new view being displayed with a red background?
- (void)viewDidLoad
{
[levelButton2 addTarget:self action:#selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
//MORE CODE
}
- (void) clickButton
{
NSLog(#"Clicked Button");
UIViewController *myViewController = [[UIViewController alloc] init];
myViewController.title = #"My First View";
myViewController.view.backgroundColor = [UIColor redColor];
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
//[self.navigationController pushViewController:nextController animated:YES];
}
-(void) clickButton
{
NSLog(#"Clicked Button");
MyFirstController *myViewController = [[MyFirstController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
}
Then after go into the MyFirstController.m file and
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.title = #"My First View";
}
return self;
}
I hope it will help you.
You havent used or mention NIB file in that controller..Add NIB file or else make set root view controller of a navigation with a view controller and push the view controller
You have to change your IBAction method a little bit as,
- (void) clickButton
{
NSLog(#"Clicked Button");
MyFirstController *myViewController = [[MyFirstController alloc] initWithNibName:#"MyFirstController" bundle:nil];
myViewController.title = #"My First View";
myViewController.view.backgroundColor = [UIColor redColor];
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
//[self.navigationController pushViewController:nextController animated:YES];
}
HI
I am working on UITablview based project. i like to load a new view when ever a cell got click. i am using following code in didselectRowAtIndexPath delegate method.
The below coding is not showing any error but new view not get load and [self navigationController] is returning null.
inside Viewdidload function [self navigationcontroller] returning proper value. but inside Delegate method [self navigationcontroller] returns null.
/// inside appDelegate class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.viewController = [[LAMainViewController_iPhone alloc]initWithNibName:#"LAMainViewController_iPhone" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc]initWithRootViewController:viewController];
[window addSubview:controller.view];
[controller release];
[window makeKeyAndVisible];
return YES;
}
/// inside LAmainviewcontroller.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
//self.navigationController.navigationBar.backgroundColor =[UIColor clearColor];// .title=#"test";
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *materialPlistPath = [[NSBundle mainBundle]pathForResource:#"materials" ofType:#"plist"];
materialList = [[NSArray alloc]initWithContentsOfFile:materialPlistPath];
materialTable.backgroundColor = [UIColor blackColor];
NSLog(#" dud kiad navigationController %#", self.navigationController);
//2010-10-20 15:22:03.809 LabAssistant[17368:207] dud kiad navigationController <UINavigationController: 0x5f3b160>
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
NSIndexPath *indexPath = [materialTable indexPathForSelectedRow];
[materialTable deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil] autorelease];
materialPropertyListView.chemicalName = [[materialList objectAtIndex:[indexPath row]] objectForKey:#"materialProperty"];
[[self navigationController] pushViewController:materialPropertyListView animated:YES];
NSLog(#"%#",[self navigationController]);
///2010-10-20 16:20:42.634 LabAssistant[17656:207] navigationController (null)
}
please help me to fix this issue.
thanks!
Remove the autorelease from the init statement. Actually the viewcontroller is getting released before it gets pushed.
instead of
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil] autorelease];
try this
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil];
Hope this will solve your problem.
I think the table view delegate is called before the navigation controller is set to the view controller.
Can you try reloading the tableview [tableview reloadData]; in viewWillAppear or viewDidAppear?