I have a UINavigationController that displays several buttons on screen. They all simply use the line:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:nil];
[[self navigationController] pushViewController:newView animated:YES];
to transition to the next view. I have one such view controller however that results in a crash at this very line ONLY on iOS 5. It works perfectly fine on iOS 6. I am baffled. There are no real details to the crash. It is a SIGABRT that highlights the main.m line:
exitStatus = UIApplicationMain( argc, argv, nil, NSStringFromClass([ApplicationDelegate class]));
I have no clue...
You Need to unCheck the Auto Layout.
And make sure you are changing here also.. select ios 5.1
Try this line:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:[NSBundle mainBundle]];
in place of:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:nil];
I have experimented a similar issue an here are the steps that I feel need to be considered:
(if you are using xib file) like Venkat Manohar Perepa mentioned, check that Use Auto Layout is turned off as it is an iOS 6 specific feature.
(if you are using xib file) look at the content of the xib file that is used when presenting your viewcontroller and check that there is no class that are iOS6 specific (e.g: NSLayoutConstraint)
Last (and that was the issue I was facing) you should check if the crash appear on a device that has iOS5 installed. If it doesn't but still crash on the simulator remove the application you have installed by choosing iPhone Simulator > Reset Content and Settings.
Related
I built an iPhone app "using xib" with 5-6 screens. Now I want to auto-resize the display for iPad. I am using xcode 4.6.
Do I have to rebuild the entire code using storyboards? It will be a very tedious work. Is there any solution for this?
You'll need to create only new xib files for iPad and name them as ViewController_iPhone.xib and ViewController_iPad.xib and when switching your views, just put a simple condition
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPad" bundle:nil];
} else {
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPhone" bundle:nil];
}
use autolayout and everything will be done automatically
if not autolayout, then making 2 xib will be a better option. Make ipad size xib with the same name and put ~ipad after classname.
Like if you xib name is myClass.xib and create other one like myClass~ipad.xib.
I'm new to programming on Xcode and can't really find out how to call the SecondViewController window by pressing a button. The button is called Ingredients; I tried entering "-(IBAction)Ingredients:(id)sender; in the ViewController.h and but then saw that there was the FirstViewController.h and SecondViewController.h, same with First and second ViewControllers.
Anyways, what I wanted to do was be able to click the "Ingredients" button and make it go to a completely different window, with a different background, and other texts as the first one. I'm not sure if I'm explaining myself correctly :(. Let me try an Image:
First of all, get some basic knowledge about Objective C. Go to Apple developer website and you will get tons of tutorials & sample codes to learn.
Now, for your question:-
In firstViewController.m
First import SecondViewController.h
On button click:-
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
As I can see you are not using story board so simply call:
FLSecondViewController *object = [[FLSecondViewController alloc] initWithNibName:#"FLSecondViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:object animated:YES];
Why go for another window? a View controller may be enough,set up a navigation controller and push the second viewcontroller.
a sample tutorial on navigation controller
- (IBAction)Ingredients:(id)sender
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentModalViewController:secondViewController animated:YES];
}
edited: Typical an iOS app has only one window which acts as a container for views, so you work most of time only with views. Change one view with another depend on desired content to be presented.
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 have an universal app that I am trying to share a viewController code with. I have this:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
AboutController *screen = [[AboutController alloc] initWithNibName:#"iPhoneAboutController" bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
}
else
{
AboutController *screen = [[AboutController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
}
Although this is loading, and when I step through the code, it does hit the xib for the iPhone but it seems to always be loading the iPad version. I know this because in the xib file for the iPhone, I have manually added different background images and it never shows. In the iPhone simulator it shows the iPad version where it is off screen.
Also, if I step through the code in the controller, it does show that the load is the iPhone yet display is all iPad objects. In the iPhone xib, I do have the Files Owner set to the AboutController.
This is the first time I am attempting to "share code". I know I can just create separate class files with the same code but this seems senseless. Any help is greatly appreciated.
Geo...
For starters: make sure you don't override nib initialization in your AboutController.
If not, try cleaning your project (also delete your app's folders in ~/Library/Developer/Xcode/DerivedData). Also uninstall the app from device and then rebuild.
My app is crashing when I navigate two view controllers in my application. For example, if I do this sequence:
RootController
ViewControllerA
ViewControllerB
ViewControllerA
My app crashes.
It crashes when I pressed the back button in ViewControllerB. So, It seems like it is with two or more ViewControllers being pushed. Each by themselves work.
I don't know why.
This is the code I am using to invoke new views.
salesViewController *anotherViewController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//confirmViewController *anotherViewController = [[confirmViewController alloc] initWithNibName:#"confirmView" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
Thanks in advance.
Good news is that your code to create new views is just fine. Bad news is that it's somewhere else. I found this conversation on the net that seems to be a similar issue.