Starting with an empty project here...
If I make a UITableViewController and make a segue from a prototype cell to some other UIViewController using the Ctrl + Click method, nothing happens. It is of the modal variety.
If I use the same method to segue from a navigation bar button it works just fine, but when I run the iOS simulator I can't even select the table cell. It's just completely unresponsive.
I was under the impression that I don't need to write any code for a simple segue such as this to work, is this false?
Edit: Fixed the issue. For those as new as I, remember to make sure "selection" is enabled in the TableView, AND TableCell Attributes windows.
On the Storyboard, Right click on the prototype cell and Under "Triggered Segues", from "selection" make your segue to desired Viewcontroller
For me, this was a combination of:
making sure I was subclassing UITableViewCell,
making sure the Segue had an identifier assigned to it in the Attributes Inspector, and
I was setting a reuse identifier for my subclassed UITableViewCell in the Storyboard's Attributes Inspector (NOT programmatically).
Did you set your cell to static?
Also have a look in this amazing tutorial in how to archive what you are looking for.
Related
Ok, I haven't been able to find a definitive answer to this. I'm on Xcode 6 working with Swift and a UISplitView. I have multiple detail views in storyboard and I want to be able to replace my detail view with another when selecting from a tableview. In Xcode 5, I was able to drag multiple segues from my prototype cell and use performSegueWithIdentifier. In Xcode 6, I can only have one segue coming from my prototype cell.
What's the best way to go about this?
One type of cell, one segue. This seems to be a logical and useful system constraint.
One solution is to just create more cell types with different cell identifiers.
Alternatively, if you have another way to determine which segue to use, draw all segues from the view controller instead of the cell. You can attach the necessary row object information in the sender object when calling the segue from the cell selection method.
You can create as many segues as u want from viewcontroller and give each seuge an different segue Identifier in IB, and the call each with performSegueWithIdentifer method
My program does not have an explicit table. It’s only table comes from “Search Bar and Search Display Controller” view as searchDisplayController.searchResultsTableView. So to create it’s custom TableViewCell, I use a xib file. Now I need to segue from the custom cell defined in the xib file to a ViewController defined in the storyboard? How do I do that?
stated differently: How to segue from a custom TableViewCell of “searchDisplayController.searchResultsTableView” to a ViewController
back story How do I add storyboard-based Header and CustomTableCell to a “Search Bar and Search Display Controller”
There seems to be an answer already but I don't get it: Segue from Storyboard to XIB
As with any table view, you should be able to set the UITableViewDelegate and UITableViewDatasource delegates on the searchDisplayControl class. And then handle segue event in the didSelectRowAtIndexPath method. I've never played with search display controllers as I typically break apart search bar and table views when I do anything search related for the sake of flexibility, and how you're saying you want to use prototype table view cells in a tableview within the storyboard.
But, if you're set on using the searchDisplayController, you could possibly get away with something like this..
You can't segue from one XIB -> Storyboard, or between 2 different storyboards.
You can pass a reference to the viewController to each tableViewCell, and access the segue that way if you'd like. However, I'd probably use protocols/delegates personally in this situation for the sake of future flexibility.
As we discussed in comments above, it's better to avoid UISearchDisplayController since it's deprecated in iOS 8.
So it would be better to use something like that https://github.com/alexbutenko/SimpleUITableViewSearch
You can use self.navigationItem.titleView = searchBar to embed search bar into navigation bar. If you have any issue just check code sample.
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 have 2 errors
"Illegal configuration. Connection "cell" cannot have a prototype object as
its destination"
Connections dont duplicate, cells are empty, without other controls in them. I try to clean project and rebuild it, but it didnt help me. How can I fix it? Thank you
Are you trying to link outlets of the cells (or elements of the cells) directly to the view controller? That would be a problem.
If you want your table view to always have the same content, you can change its content to "static cells" in the storyboard, and then you can link it like that.
If you want the table view cells to change dynamically, you cannot do it that way. You need to create a UITableViewCell subclass for your cells, and create the outlets there.
If this doesn't help at all, please explain your problem a bit better.
You probably have an outlet from something like your view controller that's connected to a prototype cell in a table view. An outlet is a to-one relationship. The cell is going to be instantiated many times, so this doesn't make sense, and is an error.
The problem might be that the outlet from the ViewController was not connected to the desired object at all, although it might be connected from the desired object to the ViewController.
for example: the IBAction outlet can be seen from the UIButton's connection inspector for "touch up inside" as linked to the ViewController's IBAction method, but the ViewController's connection inspector will not link the IBAction method to the UIButton.
Same error when I copied/pasted the admob banner view from the official sample into my tableViewCell and connected the IBOutlet from viewController. So, Tiago Lira's explanation worked for me and I created the custom cell class and added banner iboutlet there. Thus the compile time error got resolved. The above question should be accepted.
The only reason for this error is that you have copied a storyboard item- It might be whole view controller or any sub element like the view, button, and label etc. So now the problem is that they have linked each other and now you have to find what is it and delete it.
But if you have copied the whole view controller and you have checked
all possible links you could but still you getting error then this
trick is for you- Copy the main view of that view controller and
delete that VC then a make new VC and paste the copied view in that
VC, so your constraints are safe you just have to give top, bottom,
left and right constraints for the main view.
I found a solution. I delete and add new cell many times, and finally project build without errors
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.