iOS 5: Pushing a view from a button - ios5

I am trying to push a view from a button's IBAction and I am getting the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebView initWithCoder:]: unrecognized selector sent to instance 0x68902b0'
Code:
-(IBAction)showWebsite:(id)sender {
NSLog(#"Web View!!!");
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"web"];
[self.navigationController pushViewController:vc animated:YES];
}
Any idea what could have gone wrong?
_(IBAction) is connected to TouchUpInside

Make sure the .h of the second view is imported into the .m of the first view.
If you are using storyboard and just want to switch from one view to another view via a button you can place a button on the first view drop a second uiview controller onto storyboard then right click on the button and drag the connection to the second view.
To go back to the first view, repeat the process only this time connect the button on the second page to the first view.

Related

Modal segue not working from code

I've already spent the whole day in an issue and did not find a solution yet. I have a UITabBarViewController and I am trying to fire off a modal segue from one of its tabs. I've already created the view I want to segue to, created the segue itself (from the tab's view controller to the target's view controller) and the identifier. In order to test my segue I created a UIButton in my tab and wrote the following code on its action:
[self performSegueWithIdentifier:#"showProductInfo" sender:self];
The modal segue worked fine. But if I try to write the same code to be performed somewhere else (inside a specific method that is called after I receive a web service response) the segue simply does not work. I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'showProductInfo''
This is driving me crazy! Any help is more then welcome.
Editting:
Some additional findings:
If I take off the performSegue from the method I am currently using (which by the way is called by DidFinishLoading) and put it on ViewDidLoad the segue is performed successfully.
Thinking that it could be a thread related issue I included the performSegue inside a dispatch_async(dispatch_get_main_queue()... But the error is the same !
If your destination viewcontroller is inside a navigationcontroller, then take a look at this question:
http://stackoverflow.com/questions/8041237/how-to-set-the-delegate-with-a-storyboard
Furthermore, from the error it looks like the segue you are trying to perform is not attached
to the viewcontroller you are starting from. So,Try to remove the seque and drag it from the
viewcontroller.
The current view controller must have been loaded from a storyboard. If its storyboard property is nil, perhaps because you allocated and initialized the view controller yourself, this method throws an exception.
Make sure you have Storyboard ID for your destination VC (in this example myViewController).
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:#"MyController"];
[self.navigationController pushViewController:myViewController animated:YES];

Creating a logout button on iPhone app?

I have an app using storyboard. The layout is: Nav Controller > Login View Controller > Tab Bar Controller and each tab has a Nav Controller pointing to the UIViewController for that tab. I'm trying to create a log out button that would remove the TabBarController and go back to the Login View Controller. My code is as per below:
// In log out function
[self.tabBarController dismissViewControllerAnimated:YES completion:nil];
[self performSelector:#selector(patchSelector) withObject:nil afterDelay:0.3];
-(void)patchSelector{
[self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
}
I keep getting the following error:
*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'presentedViewController for controller is itself on dismiss for
I tried reading the following regarding this:
No visible interface for dismissModalViewControllerAnimated:completion
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
UITabbarController dismiss modal UINavigationController
However, none of the above helped with the error i'm getting. Is there something i'm missing in this? The error seems to indicate that the current vc is among those getting cleaned up.
When I remove my very first UINavigationController (the one before login screen) and I change the first line above to this: [self dismissModalViewControllerAnimated:YES];, it works...but only if I make it a modal segue. Easiest solution. Not sure why my original issue was, but i was able to get around it this way atleast!

Xcode4: How to create a menu for a game?

I have a game with 4 game modes. the problem is that I want to create a main menu to choose a mode, because instead of that menu there is a TabBar. I'm trying to do that putting each mode in different .xib files, and create an other .xib file for the menu.
Menu.m:
-(IBAction)PlayMode1:(id)sender{
ViewController *Mode1 = [[ViewController alloc] init];
[self presentModalViewController:Mode1 animated:YES];
[Mode1 release];
}
with this I'm getting this error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '- [UIViewController _loadViewFromNibNamed:bundle:] loaded the "ViewController" nib but the view outlet was not set.'
I checked that "view" is linked to "View" on IB so I don't know what to do...
I'm not an advanced developer, thanks for helping!
You should try to do the following:
-(IBAction)PlayMode1:(id)sender{
ViewController *Mode1 = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentModalViewController:Mode1 animated:YES];
[Mode1 release];
}
Seems like you forget to put initWithNibName inside the allocation of the view.
Also, make sure that your ViewController.xib is the correct name of the view controller and check if it has the correct outlets linked.
Check View Identity > Class Identity is set too. If not, type in the name of your controller, ViewController
EDIT
Remove everything in the xib, "Window" and "ViewController".
Drag an UIView on the left column and set its outlet.
Click on File's Owner and then, on the Inspector, Identity inspector section (third one from the left), type in the class of your view, `ViewController´.

Navigation from UIViewController to a UITableViewController

I'm trying to navigate from a UIViewController to a UITableViewController with this action button. Obviously I'm doing something wrong so it's missing the UINavigationController linked to the UITableViewController in my storyboard. Or something like that. This code displays the TableView when I press the button, but navigation bar is missing so there's no way of going back and if I swipe through the tableview the app crashes.
-(IBAction)nextButtonPressed:(id)sender{
ResultsTableViewController *nextController = [[self storyboard] instantiateViewControllerWithIdentifier:#"Results Controller"];
nextController.objectsArray = resultObjectsArray;
[self presentModalViewController:nextController animated:YES];
[nextController release];
}
Should I link the UINavigationController with the UIViewController instead of the UITableViewController, will that work? Or should I target the code above for the UINavigationController instead? How to do this simple thing? Thanks.
EDIT 1:
Adding the Navigation Controller to the UIViewController instead and push to the TableView with it like this:
[self.navigationController presentModalViewController:nextController animated:YES]
didn't solve the issue. It still crashes when swiping.
EDIT 2:
If I do like this:
[self.navigationController pushViewController:nextController animated:YES]
it crashes once the tableview is visible on screen. I get a glance at the navigation bar with "back" button now though. This is crash report from this:
-[__NSCFType isViewLoaded]: unrecognized selector sent to instance. Rødvinsguiden[318:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType isViewLoaded]: unrecognized selector sent to instance 0x6b9d2e0'
you're forgetting to push WITH the navigationController of your current view, instead your just pushing the new viewController without it.
[self.navigationController presentModalViewController:nextController animated:YES]

crashing on ios device while navigation using UIModalTransitionStylePartialCurl in xcode 4

i am using UIModalTransitionStylePartialCurl on the ios 4 device,in my test app i have 2 classes where a single button in each class, in first page onclick of the button it ill navigate to 2nd page (by curling the page up) but in the 2nd page when i click backbutton its crashing but not navigating back to my first page
following is my code used for navigation
ViewController *MainWin = [[QIAViewController alloc] initWithNibName:NULL bundle:NULL];
MainWin.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:MainWin animated:YES];
[MainWin release];
this is the crash log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nested modal view controller while curled <QIAAdminPassCnf: 0x583e040>.'
*** Call stack at first throw:
If you read the documentation for UIModalTransitionStylePartialCurl, you will see that once you've used it you can't present any more modal views.
If you want to navigate back, I think you should do,
[self dismissModalViewControllerAnimated:YES];
rather than creating a new view controller instance.
You may well have added the Action twice in Interface Builder. Go to the ViewController and to the Triggered Segues on the right and "x" do delete the extra one. LOL