Navigation from UIViewController to a UITableViewController - iphone

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]

Related

TabBased app + modalview in app delegate

I have a tab-based app. The app launches with FirstViewCOntroller. I want to display modalview when same tab item First View is clicked.
I am trying to add code in app delegate in tab bar's didSelectViewController method, but I am getting error as unrecognized selector is sent to an instance. Also, warning is displayed as presentViewController method not found.
I am adding code in foll. way:
ModalViewController *modalView = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
modalView.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:modalView animated:NO completion:NULL];
[modalView release];
Please help.
Thanks in advance
PresentViewController is a method defines in viewcontroller class, so you will have to call it from the Viewcontroller class. Since you have written this code in app delegate where self is not a viewcontroller.
So I would suggest you to use FirstViewcontroller class to execute this code

iOS 5: Pushing a view from a button

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.

Unrecognized selector sent to instance from modal view controller

I am displaying a modal view controller from an NSObject.
I call presentModalViewController:animated on self.sender which is another view controller. The view controller displays fine, but when I push a button in the view, I get the following error:
-[__NSCFType buttonCancelPressed:]: unrecognized selector sent to
instance
This is how I display the modal view controller from my NSObject:
FBComposeViewController *composeViewController = [[FBComposeViewController alloc] initWithNibName:#"FBComposeViewController" bundle:nil];
[self.sender presentModalViewController:composeViewController animated:YES];
The button is hooked up to a selector in FBComposeViewController using Interface Builder.
Does anyone have an idea why I might be getting this error?
The problem is probably the binding in FBComposeViewController.xib. What is the target-action for the cancel button set to?
Why are you using self.sender? Assuming sender is a UIButton object.
Assuming, this line of code is written in a Controller Class, use:
[self presentModalViewController:composeViewController animated:YES];

Crash when instantiating ViewController from Storyboard

I have got a single view in my storyboard, which I add to my current view by doing the following :
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:#"MainController"];
[self.view addSubview:mvc.view];
The view appears, but everything I do after it appears, leads to a crash. What am I doing wrong ?
Here is an example when it crashes:
-(IBAction)showUsername:(id)sender{
[testLabel setText:#"username"];
}
Everything is hooked up in storyboard as well, so falsely linked connections should not cause the problem.
You instantiate a new view controller:
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:#"MainController"];
But you do not retain it. Your view hierarchy is, as soon you added it to another view.
[self.view addSubview:mvc.view];
So when a button is clicked, a message is sent to you IBAction, but your view controller has been released already. To prevent this from happening, retain your mvc variable, for example somewhere in a property.
#property(nonatomic, strong) MainViewController *controller;
self.controller = mvc;
I can think all reason before you show log...
Turn NSZombie on in the Product>>Edit Scheme you should get more descriptive Error showing then. Then you can add it.
Make sure your method is declared and implemented correctly. Also make sure you have IBOutlet UILabel * testLabel in your .h. The only other problem I can think of other than that is how you hooked it up. Does it only crash when you press the button?
This line is wrong this will be why you are getting the error.
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:#"MainController"];
[self.view addSubview:mvc.view];
replace it with this
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:#"MainController"];
[self presentModalViewController:mvc animated:YES];
In storyboards you are not adding a subview you are doing one of three things presenting a modal, pushing it on to the navigation controller stack or making a custom one of these.

UIViewController custom titleView crashes app

I have a navigation based iPhone app.
When you press on a cell in the tableview a new UIViewController is pushed to the navigation stack. In this view controller I am setting a custom titleView in the viewDidLoad method:
- (void)viewDidLoad {
[super viewDidLoad];
// Setup custom navigation title
[self setTitle:#"Mediaportal"];
navItem = [[NavigationBarTitleItemViewController alloc] initWithNibName:#"NavigationBarTitleItem" bundle:nil];
[navItem setTitle:[theServer name]];
[navItem setSubTitle:#""];
[self.navigationItem setTitleView:navItem.view];
…
}
Once I switch back to the RootViewController:
[self.navigationController popToRootViewControllerAnimated:YES];
the app crashes with the following error (NSZombieEnabled=YES):
*** -[CALayer retain]: message sent to deallocated instance 0x5a5fd80
From what I can see the RootViewController still tries to access the custom titleView, which was deallocated with the second view controller. Once I comment out the custom titleView part in my code the app works.
I tried to set the navigationItem.titleView to nil (as found in the apple docs) before the second ViewController is deallocated, but that doesn't help.
Do you have a hint what I can do to prevent this crash?
Thanks,
Mark.
I had this exact same error a month or so ago, exactly the same situation. It drove me NUTS.
I discovered that the viewController i was popping too hadn't been deallocated at all. I had a custom UIButton subclass added to that view however that had been deallocated when the second view had been pushed. So when popping back, the UIButton wasn't there.
Check the view you are popping back to, to ensure you've not got any classes that you are deallocating, or are being autoreleased without you knowing.
Hope this helps.
I finally found the solution for it (a quite simple one).
I have to alloc and init the navItem through its property then it is being retained:
self.navItem = [[NavigationBarTitleItemViewController alloc] initWithNibName:#"NavigationBarTitleItem" bundle:nil];