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

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!

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.

Unwind two segues

Definition of (the relevant part in) my app:
I have map in my view (MAP). User clicks a view, app reverse geocodes to get the address and segues to another view (PICKER), it lets user select from picker the name she wants for the place or go to another view and give custom name (CUSTOM).
Problem is that when I try to unwind from CUSTOM it fails.
In custom I unwind to the same method as from PICKER that I have in MAP's controller i.e.
#IBAction func unwindCancel(segue:UIStoryboardSegue) {
// do nothing as saving was cancelled
return
}
#IBAction func unwindSave(segue:UIStoryboardSegue) {
self.reloadGeodesics()
}
Below I present how I made in the storyboard the unwinding, i.e. ctrl drag Cancel (and Save) to exit and select corresponding Action segue.
These are my error messages
2015-11-02 14:58:59.753 via[19620:2883125]
-[via.LocationNamePickerViewController unwindSave:]: unrecognized selector sent to instance 0x7bb35770
2015-11-02 14:58:59.789 via[19620:2883125] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason:
'-[via.LocationNamePickerViewController unwindSave:]: unrecognized
selector sent to instance 0x7bb35770'
when I click save. via is my app name and LocationNamePickerViewController is the controller of PICKER.
I have looked many tutorials and to me I seem to be doing everything right.
Is this a problem of doing the segue from clicking Other in PICKER to CUSTOM wrongly? Does the navigation controller between the MAP and PICKER crash the compiler? From the error it looks like PICKER's controller cannot delegate the action segue call to the MAP's controller. Can this happen and if it happens how can it be fixed? Everything works fine in the PICKER, the problem is just with unwinding the CUSTOM.
The way you create unwind segue is not right,you should create segue like this
Control + drag from Location Enter VC to Map Exit
Gif
Hope this will help you
You placed UINavigationController after Map View, so LocationNamePicker controller and Location Name Enter controller is on stack of that navigation controller, so it seems it doesn't recognize Map View Controller's unwind action even you selected that action in storyboard.
Why don't you put navigation controller before Map View Controller?
I think it will not crash then.

Connecting navigation controller through button on Storyboard crashes app

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.

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