I have a UITableView within a UIViewController. Clicking on any cell results in a segue to another UITableView whose UI and elements are same as previous UITableView. In that case should i perform self segue (i.e. segue from UITableViewCell to same UIViewController ) or copy/paste the VC and make required array name changes in pasted VC. From Code Reusability point of view Self Segue seems to be a better option.
Facing following issue with Self Segue:-
If self segue is conditional i.e. e.g. if clicking on odd cell no results in segue to self while clicking on even no segue results in segue to UICollectionView , still it segues to self and then to required UICollectionView (in case of click on even no cell), not sure why? Anyone else facing similar issue?
Note: Please note all data is fetched asynchronously in both UITableView and UICollectionView and placed on main queue.
Disclaimer: I know this is really messy, and I will refactor this into a viewcontainer later on, but I am curious about what the exact problem is here
I have a viewcontroller with a tableview and a collectionview. I have set up the cell in the tableview to push a detailsviewcontroller upon selection. That works, but when I add a collectionview on the same viewcontroller, it does not work.
However, if I add the function at didSelectItemAtIndexPath, the function does get triggered, so I am pretty sure it is not a view issue but a storyboard one.
Can someone tell me definitively if there is a limitation with using Unwind Segues with UITableViewCell or if not how to achieve this?
I can successfully implement an unwind segue from my second view controller to my first - triggered using a simple UIButton.
However, when I try to use a UITableViewCell to create the unwind segue (drag from the TableViewCell to the green Exit icon then I do not get an option for Action Segue. Instead I get options for "Selection Segue" and "Accessory Action".
How can I trigger the unwind segue on selection of a UITableViewCell?
Selection segue will fire when you select the cell. Accessory action will fire when you tap the cell accessory. unwind: underneath the Selection Segue is the one you want to choose here:
Ok. I'm a little embarrassed at my error here. I hadn't created an outlet for my UITableView and was instead using a tableview that I had created and added through code in my ViewController. Therefore the "Scene Exit" that I hooked up to the UITableViewCell on my storyboard was never being called (because the UITabelViewCell that it was hooked up to was not the one that was visible when the app ran)
I simply created an outlet to the table view and used that and all was fine. I'll put it down to my newbie status :-/
I am new to iOS development, with a couple of years of Android experience. I started directly with XCode 5 and the Storyboard paradigm. I like the visual approach to sketching out the flow of an app, but IMHO, it does not really force component reuse, or maybe I do not know how to do it.
I have an actual problem, which is the following: Instead of the typical master-detail approach, I have a situation, in which clicking on a TableView cell forces a push to another TableView, which looks the same and behaves the same way. There are two specific types of a TableViewCell that I want to reuse across the whole application, so I can't just duplicate the first TableViewController several times. I need changes in one type of TableViewCell to be affected everywhere, same for the look and behaviour of the Tableview. Sort of like reusing a component, you get the picture I hope.
I tried creating a custom TableView and TableViewCell in a separate xib file, connecting it to a custom controller class. Yet, when I want to reuse that controller class in the storyboard, I can't make a segue from the cell to the next one, because only view controllers are displayed, but no views inside.
Maybe, I am doing it all wrong. Perhaps, I should make a single controller, and force it to seque to itself if possible, no idea.
What would you do?
You can do programatic Segue from the didselected.....
#import "someVC.h"
Then when you want to Segue to the new VC
// Create a VC and remember to set the Storyboard ID of someVC (example someVCID)
someVC *newView = [self.storyboard instantiateViewControllerWithIdentifier:#"someVCID"];
// Can't remember how this works but you can change the Transition method
// newView.modalTransitionStyle = UIModalTransition;
// If you want to pass data, setup someArray in the someVC .h with #property (nonatomic, strong) NSArray *someArray;
newView.someArray = MyLocalArray;
// Animated or not
[self presentViewController:newView animated:NO completion:nil];
If what you're trying to do is performing a segue on the same UITableView you can check this answer by Rob
I'll report what it contains for completeness:
If you're using dynamic cell prototypes, you obviously can do a segue
from the table view cell to the controller without any problem.
When you make your segue, you end up with:
But let's imagine for a second that there's some reason that doesn't
work for you, e.g. you could not have a segue from the cell (for
example, you need to invoke segue from didSelectRowAtIndexPath, not
upon selecting the cell). In this case, you couldn't use that previous
technique.
There are a couple of options in this case:
As pointed out by Chris, if only supporting iOS 6 and above, use the above technique, but (a) make sure your
didSelectRowAtIndexPath uses self for the sender and then have
shouldPerformSegueWithIdentifier only allow the segue if the sender
== self (thus when the sender is the table view cell, it will be canceled);
Perhaps even easier, just don't define a segue at all and have your didSelectRowAtIndexPath manually
instantiateViewControllerWithIdentifier and then push/present
that view controller as appropriate; or
You can use the following, kludgy work-around: In short, add a button to your view controller (drag it down to the bar at the
bottom), where it won't show up on the view, but you can use its
segues. So first, drag the rounded button to the controller's bar at
the bottom of the scene:
Now you can make a segue from that button to your view controller:
And thus, you end up with the self-referential segue again:
You must give that segue an identifier, so you can invoke it
programmatically via performSegueWithIdentifier, but it works. Not
the most elegant of solutions, but I think it's better than having an
extra scene on your storyboard.
None of these are ideal, but you have lots of options.
well.. in iOs think about it differently, if i were you i would create multiple ViewController, even if they're almost the same, and create a custom cell class, and make this cell take a configuration block.
Now for each ViewController (( or TableViewController )), you reuse your same custom UITableViewCell and just pass it what's slightly different for each case, and moreover you can also create a BaseTableViewController that will have the general configuration, and in each ViewController pass the custom changes you need.
Think about it, when you look at your storyboard you'll be able to see all your workflow, and when something goes wrong you'll be able to debug, if you have are gonna use what you suggested, debugging will be a real pain i imagine.
Anyway, try it out, and ask more if you need further clarification.
I have a storyboard that has a UITableViewController. The table view has static cells, and I've configured the cells to transition to other view controllers when tapped (by control-dragging them to set up segues). This works great.
Now I've added a row to the table, and for this row I need to transition to a UIViewController that's implemented in a different storyboard. I need to handle this one in code.
Is there a way to handle the tableView:didSelectRowAtIndexPath: for this one row in code, while letting the storyboard handle the rest of the rows which already have transitions defined?
I tried calling super within the tableView:didSelectRowAtIndexPath: to invoke the "default" behaviour, but that doesn't work (undefined selector on UIViewController). I want to invoke the storyboard's behaviour for all the rows except the one I want to handle programmatically.
Sure, you can do that. Implement didSelectRowAtIndexPath, and put in an if statement that executes the code you need to go to the other storyboard controller only for the row that you just added (and do nothing for any other row).