Segue issue with SWRevealViewController - ios

I'm trying to segue from side menu page of SWRevealViewController and transfer data to another view controller. It is crashing and I'm getting this issue ` -[UINavigationController setStr1:]: unrecognised selector sent to instance 0x7f8c92224c80 '
while I'm using Reveal View Controller Push Controller method to push to the other view controller.
On the other hand in other view controllers I'm using SHOW instead of SWRevealViewControllerSeguePushController and it is working fine not crashing. I'm using storyboard.
Please where would be my issue?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"TESTTEST"]) {
ViewController *destViewController = segue.destinationViewController;
destViewController.str1 = #"data pass";
}
}

The error indicates that the segue destination view controller is a navigation controller (which consequently doesn't respond to the setStr1 selector). So it looks like your ViewController is embedded in a navigation controller in the storyboard. If so, change your code as follows:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"TESTTEST"]) {
UINavigationController *navigationController = segue.destinationViewController;
ViewController *destViewController = navigationController.topViewController;
destViewController.str1 = #"data pass";
}
}

Related

Protocols with Navigation Controller

I have a project where I have set up a protocol to pass information back from one TableViewController to a ViewController. Everything worked fine and as expected, but I decided to embed in a Navigation Controller to the TableViewController so I could add a "DONE" barButtonItem to dismiss the Controller when the user is done. Since embedding in the navigation controller, the button works well, the TablieViewController looks identical, but none of its features and methods that use the Protocol and Delegate work, and if I remove the NavigationController everything works. Could someone explain how I can fix this issue? I am fairly new to iOS and objective c.
Here is the prepareForSegue method in the NoteViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.destinationViewController isKindOfClass:[ToolTableViewController class]]) {
ToolTableViewController *targetVC = segue.destinationViewController;
targetVC.toolDelegate = self;
targetVC.autoCorrectIsOn = self.autoCorrectIsOn;
targetVC.undoAvailable = self.undoAvailable;
targetVC.redoAvailable = self.redoAvailable;
}
}
ToolTableViewController.h
#protocol ToolTableViewControllerDelegate <NSObject>
#property (weak, nonatomic) id <ToolTableViewControllerDelegate> toolDelegate;
ToolTableViewController.m - example of a method called
-(void)clearInputText{
// NSLog(#"Clear Method Selected");
[self.toolDelegate didClearInputText];
}
NoteViewController.m
-(void)didClearInputText{
self.noteTextView.text = #"";
[self dismissViewControllerAnimated:YES completion:nil];
}
Since your table view controller is embedded in a navigation controller, it's the navigation controller that will be the destination view controller of the segue. Also, it would be better to use the identifier of the segue for the if statement, rather than the class of the destination view controller (I'm using "SegueToTable" as the identifier, change that to whatever you put for the identifier). Therefore, prepareForSegue should look like this,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"SegueToTable"]) {
UINavigationController *nav = segue.destinationViewController;
ToolTableViewController *targetVC = nav.topViewController;
targetVC.toolDelegate = self;
targetVC.autoCorrectIsOn = self.autoCorrectIsOn;
targetVC.undoAvailable = self.undoAvailable;
targetVC.redoAvailable = self.redoAvailable;
}
}
Your delegate methods are called just fine (based on the sample you pasted).
Since your controllers are embedded in a navigation controller now, you should use:
[self.navigationController popViewControllerAnimated:YES]
Before, you were presenting your controllers modally, that's why dismissViewController worked fine then but not now ( in the context of a nav controller).

Passing data between controllers gives an error due to complicated segue

I have a modal segue which goes from a view controller to a tab bar controller which is embedded in a table view as you can see from this screenshot:
I want to pass data between the login screen and the table view. I use the following code:
-(IBAction)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"Enter App"]){
//Pass on username so that app can set everything up for that specific user
GamesListTableViewController *gamesList = (GamesListTableViewController *)segue.destinationViewController;
if ([segue.destinationViewController isKindOfClass:[GamesListTableViewController class]]) {
NSLog(#"ENTERING PROPER CLASS");
}
else{
NSLog(#"ENTERING WRONG CLASS");
}
gamesList.userID = self.userID;
}
}
My app crashes due to the last line of code. And i checked why (as you can see in the code above) and the reason is that the segue destination is not the GamesListTableViewController, but what i am assuming is the tab bar controller. How to i work around this problem?
UITabbarController *tabController = (UITabbarController*) segue.destinationViewController;
UINavigationController *nav = (UINavigationController*) tabController.viewControllers[0]; // or some other nr
GamesListTableViewController *tvc = nav.topViewController;

navigation bar back button repeated

I have a tableView with push segue to a detailView, and in this second view a button that perform a segue to a map location.
My problem is the back button of navigation bar appear twice (different icons also) in the map location view.
I guess is something of pushing twice the navigationbar, but I can't resolve it.
and this the method that I use to perform segues, to the detail view first
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"segue_ID"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//here I pass info between views
DetailView *destViewController = segue.destinationViewController;
}
}
and to the map:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showMap"]) {
MapViewController *vc = [segue destinationViewController];
//here I pass info between views
vc.object = self.object;
}
}
Any help? please
Have you put in LeftBarButtonItem, and also BackButtonItem for your nav bar?
Try making one of them nil.

pass NSMutableArray from root view controller to pushed view controller

i have 2 view controllers the first 1 is the root of uinavigationcontroller.
in that view controller (the first) i have nsmutable array that contains custom class that i created. so far so good :).
now in the second view controller (the child of the first) there is another nsmutable array
and i want to pass to him the array from the first view controller(from the root).
so in the method:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
i used this code:
if([segue.identifier isEqualToString:#"showDetailSegue"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
tableViewController *controller = (tableViewController *)navController.topViewController;
controller.monthnames = monthnames;
}
but when i run the program and perform the segue i got this error message:
[tableViewController topViewController]: unrecognized selector sent to instance 0x9836f20
what am I'm doing wrong?
thanks to all helpers :)
segue.destinationViewController is already your second view controller
(and not the navigation controller):
if([segue.identifier isEqualToString:#"showDetailSegue"]){
tableViewController *controller = (tableViewController *)segue.destinationViewController;
controller.monthnames = monthnames;
}
I believe your segue point to table view controller not navigation controller. Replace your code to:
if([segue.identifier isEqualToString:#"showDetailSegue"]){
tableViewController *controller = (tableViewController *)segue.destinationViewController;
controller.monthnames = monthnames;
}
It should help.

How do I push a view controller from a custom view action using storyboards/IB?

I have a navigation controller than manages a view with a custom component that does not show up on the storyboards/interface builder. When I trigger a particular action, I would like to push on the next view controller. I can do this in code, but I would like to stick to storyboards as much as possible. Is there a way to establish this link?
Thanks
Use prepareForSegue in your (root) view controller:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"SeguName"]) {
UINavigationController * navigationController = segue.destinationViewController;
PlayerDetailsViewController * playerDetailsViewController = [[navigationController viewControllers] objectAtIndex:0];
playerDetailsViewController.delegate = self;
}
}

Resources