'-[UINavigationController setLanguage:]: unrecognized selector sent to instance 0x7f8fba7df4e0' - ios

A few hours ago this code gave me no problems, however, after updating my XCode
my XCode and removing a 3rd party framework, it is suddenly giving me the above exception. I'm extremely confused because I don't think anything's changed between then and now that could cause the problem besides updating my XCode. Can anyone see an issue?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*We check to make sure the segue corresponds to segue we created when a cell is selected*/
if ([[segue identifier] isEqualToString:#"show"]) {
/*Get a pointer to the selected row*/
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
/*Get a pointer to the ViewController we will segue to*/
ViewController *viewController = segue.destinationViewController;
/*Pass the dialect and code back to the ViewController*/
viewController.language = self.languages.allKeys[indexPath.row];
viewController.code = [self.languages objectForKey:viewController.language];
}
}
Specifically, the following two lines are causing the exception:
viewController.language = self.languages.allKeys[indexPath.row];
viewController.code = [self.languages objectForKey:viewController.language];

Your segue's destination controller is a UINavigationController, your view controller is likely the top view controller of that navigation controller. You probably want:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*We check to make sure the segue corresponds to segue we created when a cell is selected*/
if ([[segue identifier] isEqualToString:#"show"]) {
/*Get a pointer to the selected row*/
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *navController = segue.destinationViewController
/*Get a pointer to the ViewController we will segue to*/
ViewController *viewController = navController.topViewController;
/*Pass the dialect and code back to the ViewController*/
viewController.language = self.languages.allKeys[indexPath.row];
viewController.code = [self.languages objectForKey:viewController.language];
}
}

Related

Segue issue with SWRevealViewController

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";
}
}

Segue infinite loop in prepareforsegue

I have built a table view where one of the rows needs to go to a special view controller. I built an if statement into the prepareforsegue function to handle this, but I'm getting an infinite loop.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *myIndexPath = [self.tableView
indexPathForSelectedRow];
long row = [myIndexPath row];
if([_categoryTitle[row] isEqualToString:#"About"]){
NSLog(#"ABOUT");
[self performSegueWithIdentifier:#"aboutCat" sender:self];
}
else if ([[segue identifier] isEqualToString:#"ShowLocationsTableView"])
{
NSLog(#"ELSE");
LocationsTableViewController *ViewController =
[segue destinationViewController];
ViewController.categoryDetailModel = #[_categoryTitle[row],
_categoryImages[row]];
}
}
When I click on the about row, I receive no change in view and the console prints an infinite steam of "About". Any ideas how to fix this?
You must not perform a segue in prepareForSegue. That is the source of the infinite loop.
If this row is trying to perform the wrong segue, prevent it with shouldPerformSegue (and now you can do something else).
Because you have not written any code for performing the segue when aboutCat is there
else if ([[segue identifier] isEqualToString:#"aboutCat"])
{
// code for performing aboutcat
}

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.

how to give one viewController add and edit functionality using storyboard

I am using storyboard and Xcode 5. I am new to ios.
How can i give a same view controller two functionality
User can add data and edit data as well.
I have bar button in my navigation bar.
DispalyDataController 1 : UITableView
AddEditController 2 : Textfields, label simple form data
Once AddEditController 2 is filled up then it must be displayed on tableview on DispalyDataController 1
I am using below code
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AddEditController *controllerAddEdit;
controllerAddEdit.arraypassed = self.dataArray;
}
You need to set identifier by selecting an segue and move to attribute inspector
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"Edit"] ){
AddEditController *controllerAddEdit = segue.destinationViewController;
controllerAddEdit.editModeOn = YES;
controllerAddEdit.arraypassed = self.dataArray;
}
if([[segue identifier] isEqualToString:#"Add"] ){
AddEditController *controllerAddEdit = segue.destinationViewController;
controllerAddEdit.editModeOn = NO;
}
}
The problem is that your view controller is nil, you need to pull it out of the segue... Try this...
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
AddEditController *controllerAddEdit = (AddEditController *)[segue destinationViewController];
controllerAddEdit.arraypassed = self.dataArray;
}

How do I set the title on the destination view controller during prepareForSegue:

I want to simply set the title on my destination view controller so that it shows in its navigation controller's navigation bar in the prepareForSegue: method however setting its title or navigationItem like so:
[segue.destinationViewController setTitle:#"doesn't work"];
[segue.destinationViewController.navigationItem setTitle:#"this either"];
doesn't work possibly because the destination's view controller's view isn't loaded yet. Can I do this without creating a custom destination view controller?
Try accessing your ViewController that is embedded in the UINavigationController like this.
First you give your segue an identifier in the interface builder, then you access the segue in the prepareForSegue method and set the title by accessing the topViewController property of the navigation controller you segue to.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"yourSegueIdentifier"]) {
UINavigationController *navController =
(UINavigationController*)[segue destinationViewController];
YourViewController *destViewController =
(YourViewController* )[navController topViewController];
destViewController.navgationItem.title.text = #"Your new title";
}
}
This is for a segue into another UITableView
Set a public NSString property in the destination UITableViewController file.
#property (strong, nonatomic) NSString *navBarTitle;
Override the setter in the .m file just to be sure.
- (void) setNavBarTitle:(NSString *)navBarTitle
{
_navBarTitle = navBarTitle;
}
In the originating tableView's segue method, pass whatever string you need in the title.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString: #"userDetails"]) {
UsersActivitiesTableViewController *destinationController = segue.destinationViewController;
//Get the index path of the cell the user just clicked
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//Grab the object from the array of users if the next view requires a specific title for a user name etc.
UserMO *thisUser = [self.users objectAtIndex:indexPath.row];
//Pass the string you want as the title to the public NSString property
destinationController.navBarTitle = thisUser.name;
}
}
And now for the important bit....
In the destination controller, get the top controller of the view and set the title property, after the view is loaded, and before it has been displayed:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController topViewController].title = self.navBarTitle;
}
If you want a static title this can now (i.e., in Xcode 4.6.3) this can be done in Storyboard simply by setting the title in the nav bar on the relevant view controller.
If however you want the nav bar title to change according to what view is being segued to, e.g., a detail of a particular table row, as far as I know that needs to be set programmatically.
It took me FOREVER (newbie, sigh!) to figure out how to modify Julian Vogels' correct answer to call the key I wanted to use. Here's what worked:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"DetailSegue"]) {
// Fetch Item
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDictionary *item = [self.groceries objectAtIndex:[indexPath row]];
// Configure Detail View Controller
TPDetailViewController *vc = [segue destinationViewController];
vc.navigationItem.title = [item objectForKey:#"name"];
[vc setItem:item];
}
If the segue is a push segue - which it should be if you're using a UINavigationController - then the destination view controller is automatically added to the window hierarchy, and you don't even need to identify the UINavigationController:
if ([segue.identifier isEqualToString:#"yourSegueNameHere"]) {
[segue.destinationViewController setTitle:#"yourTitleHere"];
}

Resources