Add button in UITabBarController in Storyboard - iphone

I have the following storyboard:
In the tab bar controller I have a add button with a segue to a view controller. I need to use the method "prepareForSegue:" because I need to transfer an object but in the Repositories Table View doesn't fire the method.
How can I detect the method "prepareForSegue:" in the Repositories Table View? Is it possible?

I suppose for "detect the method prepareForSegue" you mean "identify the right segue in the prepareForSegue method".
You do this by using [segue identifier] and the string comparison method isEqualToString: to compare it to what you set the Identifier to be in storyboard.
Also, make sure that the button, table view cell, button or other element is attached to the right segue. You can of course do that in storyboard as well. If you need to do it in code e.g. because the button is created programmatically, you will have to call the segue yourself. In the button handler you just use
[self performSegueWithIdentifier:"SegueIdentifier" sender:self];

Related

Possible to have all cells segue to same view controller?

Instead of control-dragging every cell to the other view controller, is there a way to make them all segue to the view controller more easily? I would also need to add a Segue Identifier to the individual segues as well.
That is exactly why you have a tableview delegate method.
– tableView:didDeselectRowAtIndexPath:
whatever cell in the table this method will get invoked and there you can call for whichever transition like push,model etc programmatically in code.
This sounds like something you should do programmatically rather than in interface builder. You'll want to set the selection action for the cells to trigger the Segue.
You can create a manual segue from one view controller to another. Just select view controller from the bottom bar (where you see first responder and all) and ctrl drag to other view controller. Select the segue and give it a unique identifier (TransitionSegue in this example) from attributes inspector. From code call the segue whenever you want a transition.
[self performSegueWithIdentifier: #"TransitionSegue" sender: self];
Hope this helps.

Storyboard: Condition segue transition for navigation (push)

I am new to storyboard and xcode (using 4.6)
I m using Navigation Storyboard with push segue.
I would like to implement a select snap view, that if have minimum 1 snap selected - the segue would work. Otherwise, the user should stay on the same view.
I created 2 UIView: SelectSnapsViewController and ShippingDetailViewController.
In SelectSnapsViewController.m I added the following:
- (IBAction)nextButtonPressed:(id)sender
{
looseDataAlert = NO;
[okkkBtn setFrame:CGRectMake(116, 272, 72, 37)];
if ([appDelegate.selImageDetails count] == 0)
{
label1.text = #"To proceed you need to add snaps.";
[self openAlertView];
}
else{
[self performSegueWithIdentifier:#"MySegue" sender:self];
}
}
When I debug the code - I see that the it always fall in else case of condition, however the segue (transition to the new view) still happens.
How can I prevent the user to be transferred to the new view?
There are two ways to implement conditional segues.
1) Configure the Segues as 'manual' from the ViewController and invoke performSegueWithIdentifier conditionally within your IBAction method that you wire up to event handling for your button.
OR 2) Configure the Segue as a 'Triggered Segue' from your button and implement - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender in your view controller to perform the conditional logic.
Are you saying that you only want to perform the segue if a condition is true?
If so, instead of creating the segue directly from a control or table cell, create a triggerless segue. A triggerless segue has the view controller as its source, and it won't ever fire automatically. Instead you can fire it programmatically any time you like, including from an IBAction.
To create a triggerless segue, start control+dragging the segue from the containing view controller icon in the scene dock at the bottom of the scene. Drag to the destination scene like normal, and pick the segue type. Select the segue, and in the inspector, choose a segue identifier.
At runtime, when you want to perform the segue, invoke -[UIViewController performSegueWithIdentifier:sender:]. You can pass any object you'd like for the sender, including nil. If the sender has no use to you, pass nil.
So, in summary:
Create a triggerless segue from the view controller to the destination scene
Set an identifier for the segue in the inspector
At runtime, and form code, call -[UIViewController performSegueWithIdentifier:sender:] when you want to trigger the segue.

Why a bar button item on a NavigationViewController won't trigger an IBAction

I have a pretty basic app I am working on that uses a navigation view controller system. One of my view is a table view that I added a bar button to in the story board. This bar button is just a basic add button for adding a new item to the table view. I identified the segue for use in my prepare for segue method and then I created an IBAction for the button as well.
The segue pushes to my next view just fine and passed my desired object, but the action never triggered. I ended up having to put the code for the IBAction in my prepare for segue method to get it to work.
I'm just wondering why IBAction was never triggered.
1) remove the segueNamedFoo you have created from the button to the destination view controller
2) create a manual segueNamedFoo push segue by CTRL-dragging from the leftmost small icon at the base of the origin view controller to the destination view controller
3) in your - (IBAction)doStuffBeforeSegue:(id)sender method which you have connected to your button perform the tasks which you want and then call [self performSegueWithIdentifier:#"segueNamedFoo"]

pushViewController from Prototype Cell

Quite simply, how do I push a new view controller from a prototype cell within a storyboard? I have a tableView reading data from a plist file, and its one default prototype cell on the storyboard. Then, I have another view controller in the storyboard I need to link to the tapping of a cell on the table view. How can this be accomplished?
Simplest thing would be to Ctrl-click on the prototype cell and drag the line onto the view controller that you want to transition to. It should prompt you for the type of transition—"push" transitions cause the new view controller's view to slide in from the right; "modal" transitions cause the new view to slide in from the bottom. Assuming you're using a navigation controller, the navigation bar should configure the back button automatically. You shouldn't need to write any code to achieve the behavior described in your question.
In your storyboard, link your prototype table view cell to your view
controller with a segue. Make sure to give the segue an identifier in
its Attributes Inspector.
In your TableViewController class,
implement - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
In the prepareForSegue: method, get the NSIndexPath of the row the user tapped with [self.tableView indexPathForSelectedRow]
Use the indexPath to get whatever data you need from your plist. Configure the view controller by using the destinationViewController property of the UIStoryboardSegue parameter passed into prepareForSegue:.

How to popViewController from button click of custom UITableViewCell

I have a button in a custom UITableViewCell. Its UITableView is controlled by a UIViewController. I would like to return to the RootView when that button is clicked.
I am trying to use
[self.superview.navigationController popViewControllerAnimated:YES];
in the target Action of the button, which is in the UITableViewCell.m file. However, it doesn't recognize "navigationController" because it is not in the stack.
How can I return to the RootView when that button is clicked?
Views have no explicit relation to controllers and views cannot be in the controller stack. Set the button target to be a UIViewController instance and in the action method call:
[self.navigationController popToRootViewControllerAnimated:YES|NO];