Connecting navigation controller through button on Storyboard crashes app - ios

I am using a Storyboard for the first time.
Here is a picture:
My app is a TabBar application. From the 'Main' screen I have a settings button, which I would like to connect to the SettingsViewController, which I have embedded in a Navigation Controller (because it has to continue in that manner - to other parts of the settings screen).
Another picture:
NOW: I have tried connecting the settings button (command+control drag) to the controller (modal segue)= CRASH. Tried to connect the settings controller (modal segue) = CRASH.
Tried programmatically : creating an IBAction for the settings button an then calling the settings VC, but that crashes too.
Note: This app has many many more screens, but they all work fine. It's just the connection to the Settings VC that Is crashing the app.
Any ideas would be appreciated.
Here is the error log:

So you get the error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UITableViewController loadView] loaded the "Eab-23-IvL-view-eGY-e2-X6m" nib but didn't
get a UITableView.'
Which means that your Settings View Controller, which inherits from UITableViewController, does not have an actual UITableView in the storyboard. A fix that will definitely work is to just remove the settings view controller from the storyboard and then drag a Table View Controller in place of the one you removed. Then just proceed to give it the right class in the identity inspector and set back up all of the segues and connections!

You're using UIToolBar when there is a proper way to handle it, with UINavigationBar.
Then you can set a button, connect the button to settingViewController (control+drag), then choose modal, set a name to the segue, also control+drag the bar button item to your viewController and connect like this:
- (IBAction)btnSettings:(id)sender {
[self performSegueWithIdentifier:#"settingsSegue" sender:sender];
}
Then it should work.

Related

Error after segue to Storyboard Reference

I segue from one Storyboard where the View Controller is written in Objective C to another Storyboard where the View Controllers is written in Swift 2 and it goes through fine.
However, when I click fire the next segue in the second Storyboard, I get the following error:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'record'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
This is the code that calls the next segue in Swift 2
self.performSegueWithIdentifier("record", sender: nil)
The initial view in the second Storyboard is embedded in a Navigation Controller as well.
Also worth noting, I tried without the first storyboard and my app going directly to the second storyboard, and it finds the segue fine.
Any ideas on what could be causing the problem?
Choose the segue, go to its Attributes inspector and change the Kind from push to Modal. Let the presentation and Transition remain default.
This will work fine for you.
But if you want the segue of kind 'Push' then the first View controller which is written in Objective-C should be embed in Navigation Controller.

Cant call a segue in code (Swift)

I have a few views embedded in a navigation controller.
I've created a few segues (some from buttons to other view controllers, some from one view controller to another one.
for example I have a segue (Show) from one button to a view controller called name2, when I press the button it works great, but when I try to call it programmatically the app crashes and gives an error.
This is how I call the segue on ViewController1
self.performSegueWithIdentifier("name2", sender: self)
this is from ViewController1 to ViewController2
I also have a segue that is connected not to a button but from vc1 to vc2, gives the same error.
This is the strange error I get:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (ViewController2) has no segue with identifier 'name2''
I tried cleaning the product and also reseting the simulator.
A screen shot of my storyboard
A screen of the identity inspector of viewcontroller1 (it is actually called ViewController in my project)
A screen shot of the segue (name3)
The options of the segue :
Edit:
I found that when I connect a button as an IBAction and then call performSegueWithIdentifier("LogIn", sender: self) from the button it works correctly.
Any help?
Do not connect your Button in Storyboard Editor to the other segue (when you want to call the performWithSegue function within your ViewController1) - just connect the first ViewController to the second One.
Then you can use
self.performSegueWithIdentifier("name2", sender: self)
within your ViewController1 class.
When you set the Segue from one view controller to the other, ensure that you have correctly set the class - see image:
UIStoryBoardSegue was what mine needed.
The error says that you're looking for a segue in ViewController2 but your question states that the segue comes from a button. That would explain why it can't be found.
Try to remove the segue identifier ( name ), build ( cmd + b ), then set the segue identifier and compile. ( in storyboard of course )
Ok the answer is that I'm pretty dumb,
Whenever I was creating new ViewControllers, I was subclassing ViewController which was my first ViewController, instead of UIViewController which made it run recursivly.

Xcode: How to push to a scene with a programmatically created button

So I have a programmatically created array of "buttons" which are actually UIImageViews. All of the buttons can create an action, or give an Alert. When this button is pushed I want it to go to a scene in my storyboard. Here is the code that I've tried out that I thought would have worked:
if (b3.alpha>0.75 && CGRectContainsPoint(b3.frame, location))
{
[self performSegueWithIdentifier:#"News" sender:self];
}
I have a segue from the menu view controller to my news view controller with my Segue Identifier as News. My problem is that if I were push to the NewsViewController's class the news display doesn't register for some reason. It seemed that if i set the news scene to the initial view controller it works perfectly, and I've put a button on the scene temporarily and pushed from button to scene and that worked perfectly as well.
I've looked around for another solution but no matter what I try it either will not go to the scene in the storyboard or i'll keep getting libc++abi.dylib: terminating with uncaught exception of type NSException.
Any help would be appreciated!

DetailView Disappears After Selecting Navigation Inside UISplitView

I am facing a little issue inside my project. I have a simple IPad app that is using SplitView in Lanscape orientation. MasterViewController is a tableview while DetailView is the WebView as shown below:
The above diagram results in the following:
After that, i have put the whole thing inside ECSlidingViewController. Tapping on the "Menu" button in MasterViewController will reveal the side menu as shown below:
Now i can tap on some other option in the menu, let us say i have tapped "Contact" inside the Menu, the associated view controller will come up as shown below: (This view controller does not have any detailview)
Everything till this point is fine and exactly what i wanted!!!! The problem starts now when i tap the Menu button again to reveal the menu and select the "Navigation" again to reveal the tableview. When the "Navigation" is tapped, it shows the MasterView but hides the DetailView as shown below:
Other than that, tapping on any entry in the tableivew above will cause the program to crash with the following message in console:
* Assertion failure in -[UIStoryboardReplaceSegue perform], /SourceCache/UIKit_Sim/UIKit-2380.17/UIStoryboardBuiltInSegues.m:63
2013-03-30 13:59:58.179 19IPadIPad[5806:c07] * Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason:
'Could not find a split view controller ancestor for
'', while performing a split view
controller replace segue (identifier 'pushLink') with destination
'''
*** First throw call stack: (0x217b012 0x16bce7e 0x217ae78 0x1152665 0xa57349 0xa48b99 0xa48c14 0x6b0249 0x6b04ed 0x10ba5b3 0x213a376
0x2139e06 0x2121a82 0x2120f44 0x2120e1b 0x1d587e3 0x1d58668 0x600ffc
0x24bd 0x23e5) libc++abi.dylib: terminate called throwing an exception
Can somebody look into the problem and tell where the problem could be. Thanks in advance.
UPDATE:
After talking to the user on chat who suggested that after i tap the navigation in menu, the next thing that appears is only the masterview and splitview is actually not loaded. Looks like that is the problem but i don't know how to fix that.
UPDATE:
How ECSlidingView Is Integrated With The SplitView
I am updating the question after receiving a comment asking how the ECSlidingView is connected to the project and the SplitView.
I have created a class named 'MainSplitViewController' inherited from UISplitViewController, and connected it with the splitView in my storyboard in the identity inspector. Also i have given it the Storyboard ID of "SplitTop".
Then in my InitialViewController i have called the SplitView as the topviewcontroller as follow:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.topViewController = [storyboard instantiateViewControllerWithIdentifier:#"SplitTop"];
}
The ECSlidingView menu appears when the "Menu" button is pressed on the MasterViewController as you can see in the images above. That menu button is using an IBAction to reveal the ECSlidingView:
- (IBAction)revealMenu:(id)sender {
[self.slidingViewController anchorTopViewTo:ECRight];
}
I have also used ECSlidingViewController in a test project i was working on. I guess i am able to understan the problem you are having.
First of all this problem does not have anything to do with SplitView or your navigation controller inside it as you can remove SplitView and it will work fine. This problem is associated completely how you are integrating SplitViewController inside the ECSlidingView library.
After going through the images you have posted above, it seems like ECSlidingViewController was added to the project before you started working on the SplitView. That means in your code, the navigation menu is still connected to your MasterViewController. It should be connected to the SplitViewController.
As your updated question suggests that you are calling your SplitView in the InitialView as follow:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.topViewController = [storyboard instantiateViewControllerWithIdentifier:#"SplitTop"];
}
But the above code is just setting it to be the TopViewController. I have checked the ECSlidingView library and you will notice that the Menu table view that gets revealed is handled by the MenuViewController. That means you have to make necessary changes inside this class.
As your StoryBoard ID for MainSplitViewController class is set as 'SplitTop', you can add it in the ViewDidLoad section of the MenuViewController class where the whole array is defined that is drawing the Menu items.
Hope that helps.

Strange Error with Push Segue

I just created a calculator app with storyboards using two views. I started my simulator, and everything worked fine at first. On the first screen, I was able to use the "Calculator" button to switch to the second screen, and on the second screen I had a button to go back to the main menu. But when I switched from the main menu back to the calculator a second time, the app crashed, and the following error occurred:
2013-02-21 20:55:36.556 CTS Calculator[22637:c07] * Terminating app
due to uncaught exception 'NSGenericException', reason: 'Could not
find a navigation controller for segue 'To Calculator'. Push segues
can only be used when the source controller is managed by an instance
of UINavigationController.'
* First throw call stack: (0x15a9012 0x12b6e7e 0x650f31 0x642b99 0x642c14 0x12ca705 0x1fe2c0 0x1fe258 0x2bf021 0x2bf57f 0x2be6e8
0x22dcef 0x22df02 0x20bd4a 0x1fd698 0x260bdf9 0x260bad0 0x151ebf5
0x151e962 0x154fbb6 0x154ef44 0x154ee1b 0x260a7e3 0x260a668 0x1faffc
0x1ecd 0x1df5) libc++abi.dylib: terminate called throwing an exception
(lldb)
I am not sure why this did not happen the first time I pushed the calculator button. I have a custom segue transition going back to the menu, but not from the menu to the calculator. My navigation controller is set up fine, I believe. Any ideas what the problem might be?
Error shows you dont have a navigation controller. and you are setting segue style to push. Change the segue style to modal and give a try.
Yes. You can use push then the root view controller should be a navigation controller.
Check these links
Adding a Navigation Controller to a Storyboard
Use Storyboards to Build Navigation Controller and Table View

Resources