I've just updated to Xcode 4 had a few problems getting the app to compile but they are sorted now. However I have a major problem with the navigation of my app. I have various buttons that all fire actions that should display different modal windows using code similar to the following
- (IBAction)showMyJobs:(id)sender {
UIViewController *myJobsView = [[MyJobsView alloc] initWithNibName:#"MyJobsView" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myJobsView];
[self presentModalViewController:navigationController animated:YES];
[myJobsView release];
}
Now all this code was working perfectly before I compiled the app in xcode 4. What happens now is that the code seems to run (see it running in the debugger) but nothing gets displayed. Can anyone point me in the right direction as to whats going on.
I don't get any errors/warnings while compiling, nothing. It's driving me mad!
Any help would be greatly appreciated.
Just a stab in the dark, but try:
[self.navigationController presentModalViewController:navigationController animated:YES];
This is really late, but for what its worth - you need to release the navigation controller first and then the view controller.
Related
I have this same piece of code in two different parts of my app.
In one section it is executed perfectly, and in the other it is completely ignored. I've put in a breakpoint and watched the program go through each line of this code without loading the next xib/class it is supposed to.
Here is the code:
UIViewController *nextController = [[ClassNameViewController alloc] initWithNibName:#"MatchingView" bundle:nil];
[nextController performSelector:#selector(setDelegate:) withObject:self];
[self presentModalViewController:nextController animated:YES];
Any ideas why this might be getting ignored and not presenting my viewController?
Try using ..
[self.navigationController presentModalViewController:nextController animated:YES];
I had this code in viewDidLoad and moving it to viewDidAppear made it work.
I have a question about iPhone develop
CarDetailDetail *myview = [[[CarDetailDetail alloc] init] autorelease];
myview.detailMaintainID = self.detailMaintainID;
[[self navigationController] pushViewController:myview animated:YES];
this is work fine in iPhone 4 (iOS 4.3) and iPhone 3gs (iOS 5.X)
but iPod touch (iOS 4.2) will crash when I pop back one or two times,
memory warning will appear and has bad access error
but when I not release *myview (remove autorelease keyword) , iPod works fine...
I don't know why , some one can help me? thanks
Experiment with the YES/NO flag on the pop animation
If you find that you are getting no crash on your problem device with NO pop animation it probably indicates a timing issue of some sort.
In other words a block or web thread is trying to hit a view controller which has been deallocated already.
post your your console logs in the question too for more help.
try doing this
CarDetailDetail *myview = [[CarDetailDetail alloc] initWithNibName:<name of view contrlle> bundle:nil];
//Remove this bit of code myview.detailMaintainID = self.detailMaintainID;
[[self navigationController] pushViewController:myview animated:YES];
[myview release];
I'm having a strange problem with my UINavigationController. the stacktraces are:
which is very odd to me because all I did was:
CommonVC* cvc = [[CommonVC alloc] init];
//CommonVC is my customized viewController. and i did some setting after the init.
[self.navigationController pushViewController:cvc animated:TRUE];
[cvc release];
and after 3 times pushing and popping it crashes.
i also ran it with NSZombie but it told the zombie is the CommonVC itself.
so can anyone help me find where the problem would be?
Do you make use of delegates and set them in your view controller. If yes check if they are made nil...
I am using a tab based application that shows a presentModalViewController called "overview" that has 2 buttons on it .
In order to call it I am using the following code in app delegate:
Overview *overview = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
[self.tabBarController presentModalViewController:overview animated:YES];
When overview shows up, it has a button called that gets clicked and I am using the following code:
-(IBAction) btnLoginPressed{
[self dismissModalViewControllerAnimated:YES]; //get rid of view
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self.tabBarController presentModalViewController:login animated:YES];
[login release];
}
However the login prsentModalViewController never shows up. Can someone explain why and what I can do to show it?
Thanks
When you present a modal view controller, you do it from the view controller currently in the view.
Assuming your second modal display of a view controller is happening in Overview.m change your code to the following:
-(IBAction) btnLoginPressed {
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[self presentModalViewController:login animated:YES];
[login release];
}
You don't need to dismiss Overview first, and in fact you shouldn't as it the animations won't work in conjunction with each other.
When you ultimately dismiss login (or however deep you want to go), you send dismissModalViewController:animated: as high up as you need to. To get back to the tab bar's controller use:
[self.tabBarController dismissModalViewController:animated]
It would be well beyond the scope of your question and the time I have to answer but you should take some time and really study the docs on implementing View Controllers. I definitely recommend following Apple's code style guidelines as one suggestion to make your code much more readable (e.g. overviewViewController vs overview). It's also clear you're just learning so keep at it.
I'm looking for some advice about the best way to create a multi-view iPhone application. This app will slice left to right and right to left when a it goes from one view to another. Very similar to how a navigation-based application but without the navigation top bar.
I'm doing some tests using this code:
- (IBAction)goToSettings:(id)sender {
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:#"SettingsView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
something like UIModalTransitionStyleCoverHorizontal which doesn't exist.
So, I'm trying to do transitions, but now sure if that's the best way to do it, in terms of memory management, etc.
In summary, my application will have ~8 views, and I need to be able to navigate between them, going left to right into details, and go back to the left (previous view). What is the best way to do it?
Thanks in advance.
The navigation bar is optional in a navigation-based application. UINavigationController has a - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated method.
If for some reason that won't work, an alternative might be a paging UIScrollView, but that would be more hacky and more work to get what UINavigationController already gives you.