Segue from Custom Cell (dynamic Prototype Cell) - objective-c

Im using the Storyboard to create my UI.
I have a SplitViewController. The MasterViewController holds a TableViewController where I created a CustomCell with Custom Design.
The Cells are shown pretty good with my data.
The point is: The Custom Cell also holds an Info-Button, with should Popup a little 300x88 TableViewController with some data.
If the Cells in my MasterViewController->TableViewController where a Static one, I just would drag & drop a Segue from the Info-Button to my Popup-TableViewController.
But sadly I cant do this with a dynamic Prototype Cell... I just get the error:
Couldn't compile connections ... >> anchor >> UIButton...
So how can I implement this?
Kind Regards.

Define a manual segue dragging the whole master view onto the detail view, then add a manual target/action to your custom info button and perform the manual segue there. Of course you must set a segue identifier in the storyboard to later reference it in the code, IB will tell you if you forget to.

Instead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to cells. And when segues are ready, you can use this method for moving on to the next View Controller depending on which cell is tapped from the tableView.
[self performSegueWithIdentifier:#"yourSegue" sender:nil];
You just have to check which cell is tapped and then perform the appropriate Segue on tap using the above code and the respective segue identifier. The prepareForSegue method will be called immediately after this method is called.
Look out for the yellow button as shown below your View Screen in your storyboard.
Drag and drop a segue from that button onto the View Controller that you want to connect.
Hope this helps.

Related

Creating a segue for a TableViewController cell's detail accessory button

I'm trying to implement segueing from a tableview controller when the user taps the cell's accessory button.
I've searched on here and have some new things to try but I just wanted to ask whether in the storyboard you can actually create the segues from the accessory button, or whether you just need to create them from the tableviewcontroller.
It'll be within the accessoryButtonTappedForRowWithIndexPath that I'll want to act on the tap, but I see some answers on here say that you have to just go from the tableviewcontroller when creating your segues where as another answer said that the sender within prepare for segue would be set to the cell that contains your accessory view.
Whenever I try to ctrl drag from the accessory button in my prototype cell it just gets rid of the already existing on-selected segue I'd setup for that cell.
Just wanted to know for sure, what the best practice was before I started making all my detail accessory segues just go from the root TableViewController and passing through accessoryButtonTappedForRowWithIndexPath's indexPath (or it's row) as the sender to my prepareForSegue.
Cheers
Ok, after trying the suggestions I described in my original question I got the code all working how I wanted. I added segues from the root tableview controller and then performed them programatically within the accessoryButtonTappedForRowWithIndexPath delegate function.
I have a few Table View Controllers doing similar things in my navigation controller so I set about implementing this accessory button workflow in each of them. When i reached the last TVC in my nav controller hierarchy I didn't want selecting cells to go any further, so i changed the accessory type to just detail.
As I wasn't concerned at this stage to have the cell interaction sourced segues overwriting each other I just dragged a segue out from the prototype cell to the destination view controller. Upon doing so within the add segue popup I saw 2 options - Selection Segue and Accessory Action. I'm sure that when I first tried doing this I only had the single Selection Segue choice.
Regardless of whether this was my tired eyes missing it, or Xcode having a funny turn (as it seems to from time to time, being laggy at updated states of various files etc) I can now say in answer to my original question, all you have to do is setup your accessory action segue as required. You can have both selection segue and accessory action segues setup from the same prototype cell, and everything just works as you'd expect.
I've just updated my setup to work this way and all seems fine.
Cheers

Prototype button in StoryBoard?

My app dynamically generates buttons. When the button is clicked it creates a table linked to it. I have all the table interfaces (navigation controllers, etc.) set up in storyboard. However, my main view is the home screen where the user creates buttons. Since the button isn't already there, how do I set it up so that it creates a new instance of the tableview outlined in my main storyboard? Is there a "prototype button" in storyboard? The "#selector" action for the generated button is pointing to this IBAction:
-(IBAction)generateTable:(id)sender {
}
Can someone help me fill in the remaining code?
Also, the home screen view controller is already set up in Storyboard, with the arrow next to it.
EDIT: this picture might help understand my problem a better.
http://i.imgur.com/MdT4i1P.png
Found the answer myself quite easily. All you have to do is make a segue (with an identifier) in Storyboard from your ViewController to the ViewController you want it to connect to, then in the IBAction, just add the following.
-(IBAction)generateTable:(id)sender
{
[self performSegueWithIdentifier:#"GoToTable" sender:sender];
}

3 programmatically created UIButtons - how to go between 3 UIViewControllers using those buttons with Storyboard?

Playing around with some Objective-C (well, iOS) and have done the following... loaded some UIButtons programmatically into a UIScrollView. That works well. Though I've always just connected UIViewControllers together using control-click and drag. Now I've created buttons programmatically, I have no idea how to go from one view controller to another in a Storyboard because there is nothing to drag from!
I'm not really sure what code to post as such, because I haven't done anything that /nearly/ works or doesn't work as such. I get how to do it with XIBs. But I suppose the question is : 3 UIButtons have been created programmatically and I have 3 UIViewControllers. How do I access those ViewControllers using my UIButtons?
Thanks
In the Interface builder view control click and drag from the viewcontroller icon under the first view controller, to the middle of the second view controller. A segue will be created, selected the appropriate type.
Now select the segue and in the inspector give it a unique identifier (say 'myNewSegue').
Now in your first viewcontroller you can create a method that has the following code:
-(void)myButtonAction:(id)sender {
[self performSegueWithIdentifier:#"myNewSegue" sender:self];
}
And add this method as a target action to your button:
[myButton addTarget:self
action:#selector(myButtonAction:)
forControlEvents:UIControlEventTouchUpInside];]
A segue doesn't have to have a button at the leading end of it; you can instead draw it from an entire view controller to another. You can also give a segue an identifier, a string that's used as a name for that segue. Once you've done that, you can programmatically trigger that segue by calling -performSegueWithIdentifier:sender:.
To actually call -performSegueWithIdentifier:sender:, though, you'll need to connect the button to a target and action. If you've never done that, read the Event Handling Guide for iOS in your documentation.

Create a storyboard segue that isn't attached to any UI element?

I'm trying to trigger a storyboard segue from a UI element which isn't in my storyboard (in this case, it's a UIAlertView). As such, I can't draw the arrow from any of the existing components in my storyboard.
What's the proper way to deal with this situation? I need a segue with an identifier, so that I can call it from the relevant UIAlertView button.
You can add your segue by right click + drag from your source controller to your destination controller in your Storyboard. Then just click on the created segue and set the identifier.
You can trigger your segue programmatically like this:
// Note: In this example self is the source controller
// (the controller that holds the segue)
[self performSegueWithIdentifier:#"mySegue" sender:self];
Here is a screenshot you can use as a reference:

Table View Cell Segues not Working

I'm trying to do something very simple: set up a segue so that when you click on a cell in a table it will take you to another View Controller. The problem, I believe, originates from the fact that the TableView these cells are in is embedded in a regular ViewController (as opposed to a TableViewController), and is one of two subviews in this ViewController.
As far as I can tell, I've set everything up correctly: I embedded the ViewController with the two subviews in a Navigation Contoller, set it to be the dataSource and delegate for the TableView, and created a push segue from a TableViewCell to my second View Controller in the storyboard. However, when the app is run and a user clicks a row in the table, it merely selects the row and the segue doesn't fire at all (I've debugged it and the prepareForSegue function isn't even being called).
Is there something I'm missing here? Or is this for some reason not possible if the TableView is not the only view in its view controller?
I find that if I had recently wired the segue from the cell's accessory view, and later delete the segue and try to wire a new segue to the cell directly it does not work (using Xcode 4.6.2) -- Xcode keeps connecting the segue to the accessory view (even if there isn't one)! The way I fixed it is by selecting the cell in IB and using the connection inspector to (1) delete the original "accessory action" segue and (2) directly wire the "selection" segue by dragging from the filled circle in the image below to the appropriate destination view controller.
This may or may not help you, but I ran into this issue because I had defined two different cell types, and had provided didSelectRowAtIndexPath implementation. I had to add [self performSegueWithIdentifier:#"Whatever" sender:self] as part of didSelectRowAtIndexPath and the issue got resolved.
If you are able to at least detect row selections, you may be able to take advantage of this method.
If you have customized the cell rendering, e.g.:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
then ensure you are using the same cell identifier as specified for the prototype cell in ste story.
So in this case the 'Identifier' of the cell which hooked up the segue should be set to 'Cell'.
If you are creating the StoryBoard in Xcode then do the following:
Create a UITableViewController
Add a prototype UITableViewCell
Create the UIViewController that will be your segue target.
Control-Click on the prototype UITableViewCell and drag to the segue target.
That's it. You'll probably want to edit the characteristics of the UITableViewCell to be, for example, your subclass of UITableViewCell.
I had the similar issue.
Fix is
1. Write SegueIdentifier for the segue in Storyboard
2. Add the following line [self performSegueWithIdentifier:#"SegueIdentifier" sender:nil]; in didSelectRowAtIndexPath.
I hope this would help.
Had the same problem. Segue from a prototype table view cell inside a regular View Controller would make the app crash. In case someone have the same problem.
My solution:
If you are using a push segue make sure your first View Controller with the table view is embedded in a Navigation Controller otherwise "push segues" wont work. Also point the segue at the destination View Controller, not its Navigation Controller!
And as mentioned earlier, make sure your "segue identifiers" are correct.
at "didSelectRowAtIndexPath" I call "[self performSegueWithIdentifier:#"Your_destination_View_Controller" sender:self];