I'm currently facing something I find rather strange.
In my storyboard, there is a TableViewController filled with static cells.
I would like to perform a simple segue (a push to another view controller) when I select one of the rows.
So I "ControlDrag" from the concerned table cell to the sibling controller, but when tap one the cell, nothing happens. Next to that, I did try assigning the segue triggering to the accessory view of the cell (a disclosure button). And in that case, the segue is effectively triggered.
So here is my question : Should I use the "programmatic way" to handle the tap on the cell (tableview delegate methods and manual segue performing), or is there something I'm missing in the interface builder? And btw how could we explain the behavior difference with the accessory button view ?
Here is two screenshot
Cell selection that should trigger segue
And, the accessory action which performs the segue
I finally found what the problem was. I had a gesture recognizer attached to the view controller, and it was catching the tap event on the cell.
Related
I have a custom uitableview inside a uiviewcontroller. A segue to another tableviewcontroller will happen every time a cell is tapped on. I also have a back button on the other tableviewcontroller which allows users to segue back to the original viewcontroller. The problem happens when the unwind segue happens. After I get back to the original viewcontroller, the first cell of the tableview would be hidden right below the navigation bar, so the tableview bounds have changed I'm guessing? I have been looking everywhere but am unable to find a solution, please help! thanks in advance!
this is odd, but I'll try to explain the best I can.
I have a navigation controller which has a view. The view asks a simple question. That view then has two segues available -- one on the view for a correct answer, which is a "show" on the navigation controller and the other for an incorrect answer which is a "popover".
The segues are tied to the view and the answer box for the show and popover respectively.
I'm testing the answer on button press and using performSegueWithIdentifier to then show the appropriate window.
if (answerField.text == "2") {
println("Correct")
performSegueWithIdentifier("Correct", sender: sender)
} else {
println("Incorrect")
performSegueWithIdentifier("Error", sender: sender)
}
The problem I'm having is that if I get the answer correct, it moves fine to the next view, but it shows the "incorrect" popover view after segueing to the correct one.
I know that sounds complicated, but it's a super simple app at present. I suspect I'm just doing it wrong. Of note is that I also get an error "Presenting view controllers on detached view controllers is discouraged" which may be related.
Many thanks for any assistance anyone can provide.
D.
It sounds like you have one or both of the segues hooked up directly to the button in your storyboard, which will trigger the segue automatically on the button press even when you don't call performSegueWithIdentifier(_:) in code. You are then setting up an IBAction method which is also called on the button press, where you are then programmatically performing the segue again.
You can check this by going to your storyboard and selecting the button. Go to the connections inspector on the right, and I expect you'll see a Triggered Segues section, with an "action" triggering your "show" segue. You can remove this by clicking the cross next to the connection.
For segues that should be initiated programmatically, you should create a segue by dragging from the view controller object (rather from a control / actionable element) to the next view controller. This will create a generic segue that is only triggered by performSegueWithIdentifier(_:) in code.
As you have noticed, since your segue is for a popover presentation it will complain unless it is explicitly anchored to a particular view in your storyboard. You can still drag the segue from the view controller object to the popover view controller, but you must manually hook up the anchor: select the segue in the storyboard, choose the attributes inspector on the right, and drag from the circle in the "Anchor" field to the text field you want to anchor to.
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.
I have a UITableView loading cells from a nib. On each table view cell, there are two buttons. When the button is tapped, I need to update other fields in the view that contains the table view.
In the past I've used a delegate on the table view cell to call back to the view controller to tell it that which button was tapped and used tags on the cell to find the cell's index. The problem I'm currently facing is that this sort of behavior happens in multiple places throughout my application and delegate patterns everywhere could get messy quick.
Is there a better method to message the tableview's parent view controller when a button on a specific cell has been tapped? I need to know which cell was tapped and which button on the cell was tapped.
Yeah, the better method is to make your controller the target of the button's action method. You'll still need to use tags to get the index path of the cell the button was in. You can hook up the action method in IB, or in cellForRowAtIndexPath.
I'm using a UITableViewController that performs an action sheet upon click, which works great. I'd like to tie the Detail Disclosure to a segue. I created a segue from the cell to the next table, and added the following code:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"GroupToGroupMembers" sender:self];
}
Works great when I tap the Detail Disclosure.
Problem is, tapping on the cell now causes both the action sheet AND the segue to fire off, which I would expect.
Anyone figure out how to fire off a segue off of a detail disclosure only?
You probably have the "GroupToGroupMembers" segue hooked up to your UITableViewCell. When you do this, the segue is automatically performed when the cell is selected. This happening in addition to your regular event handling which is showing the action sheet.
Hook your segue up to your UITableViewController instead. This allows you to define your segue so that it may be performed in response to the DetailDisclosure being tapped while, at the same time, preventing the segue from being automatically performed when a cell is selected.