I am trying to create an app with multiple scenes the first two scenes connect and transition fine using a segue, but when i add a third scene and connect it with a segue nothing happens when i click the control to transition. Here is the code i have so far
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"showStops"]){
NSIndexPath *indexPath = [self.directionTableView indexPathForSelectedRow];
StopsViewController *destViewController = (StopsViewController *)segue.destinationViewController;
destViewController.routeNumber =[[feeds
objectAtIndex:indexPath.row]objectForKey:#"rtNumber" ];
destViewController.direction =[[feeds objectAtIndex:indexPath.row]objectForKey:#"Direction"];
}
}
So let me see if I got it. U have a screen that connect to two others screens right? So u need two Segues with differents identifier. Than in method prepareForSegue u will check wich one was clicked.
Something like this!
- (IBAction)firstConnection:(UIButton *)sender {
[self performSegueWithIdentifier:#"firstSegue" sender:nil];
}
- (IBAction)secondConnection:(UIButton *)sender {
[self performSegueWithIdentifier:#"secondSegue" sender:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"firstSegue"]){
// YOUR TRANSITION
}
if([segue.identifier isEqualToString:#"secondSegue"]){
// YOUR TRANSITION
}
}
Related
I'm trying to create a manual segue, which happens only if there is a certain conidition (a successful login).
The steps I have followed are these:
1) I've created a button in source viewcontroller, and i connected the button with a drag with the destination viewcontroller.
2) I set the identifier for the segue, calling it login_ok
3) I've created a -(IBAction)buttonPressed:(id)sender
Now, I tried to make an example, to see if the work or not. I wrote:
- (IBAction)buttonPressed:(id)sender
{
BOOL test = false;
if(test == true)
{
[self performSegueWithIdentifier:#"login_ok" sender:self];
}
Theoretically, the segue should not work, because i set test=false, and i said the segue should work only if test=true.
But the segue works and makes me go to the destination viewcontroller.
Why?
If you connected the button with a drag to the destination controller, it should segue anyway.
You need to connect the segue between screens and not from the button to the screen. Then, you can control your segue from the code.
You should define your segue between controllers not from button to the controller. Defining segue between view controllers is more useful than defining segue from any component to a view controller, because when you want to use a condition for any action, you can use these two methods effectively
[self performSegueWithIdentifier:#"segueID" sender:self];
and
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
For example:
- (IBAction)buttonPressed:(id)sender
{
BOOL test = YES;
if(test == YES)
[self performSegueWithIdentifier:#"login_ok" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"login_ok"])
{
YourNextController *controller = [segue destinationViewController];
controller.welcomeText = #"Hi! Test is true congratulations";
}
}
Especially passing data from controller to another one, this way is always useful.
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
}
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.
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;
}
I need help with this app I am building. If you need to see the full code, I can post it, but here is the scenario:
I have 3 UIViewControllers, SMPViewController, SMPLetterViewController and SMPDetailsViewController.
In SMPViewController I have a prepareForSegue, and an UnWind:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
SMPLetterViewController *destination = [segue destinationViewController];
destination.lblSectionText = _lblForSectionTitles;
}
-(IBAction)returnToMain:(UIStoryboardSegue *)segue{
//just return to Home page
}
In SMPLetterViewController I have a prepareForSegue, an UnWind and a button titled, “Back” that connects with the UnWind of the SMPViewController:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
SMPDetailsViewController *destination = [segue destinationViewController];
destination.lblTextLetter = _lblWordSort;
}
-(IBAction)returnToLetterList:(UIStoryboardSegue *)segue{
//just return to Letter page
}
In the SMPDetailsViewController, I have a button titled, “Home” which connects the UnWind of the SMPViewController, and a button titled, “Back” which connects with the UnWind of the SMPLetterViewController.
When I run the program everything is working properly except the Back button on the SMPLetterViewController, it keeps crashing my App. with an error telling me something is wrong with the lblTextLetter in the prepareForSegue in the SMPLetterViewController. When I comment out the prepareForSegue in the SMPLetterViewController everything works great, except I cannot transfer the information to the SMPDetailsViewController.
To me the prepareForSegue’s in both the SMPViewController and SMPLetterViewController syntax is correct so why does it not work and why is it singling out the lblTextLetter?
Any ideas as to what is wrong? Do I just need another pair of eyes as I am missing something?
Thanks for any help,
socamorti
In storyboard add segue identifier and change your prepareForSegue to something like that:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"YOUR_IDENTIFIER"]) {
SMPDetailsViewController *destination = [segue destinationViewController];
destination.lblTextLetter = _lblWordSort;
}
}
And do something like that for your second prepareForSegue as well.
This issue happens because when you run unwind action the prepareForSegue is called as well.