Configure destinationsViewController based on selectedRowAtIndexPath - swift

I got no code because im very confused. I got a UITableView, the user can create cells by naming. The cells all segue to the same UITableViewController, so far i segue the cell.textlabel?.text to the next UIViewController so they differentiates based on the name. On the destinationViewController i want the user to be able to create a deck of flashCards. These decks of flashCards should off course be connected to their respective UITableViewCell. Anyone know how you achieve such behaviour? Or a place were i can ask a question as such.
App example.
UITableViewCell (cell.textlabel?.text = DogsBreeds) ->(Segue)-> UIViewController (Containing the users customised deck of dogflashCards)
UITableViewCell (cell.textlabel?.text = HorseBreeds)->(Segue)-> UIViewController (Containing the users customised deck of horseFlashCards)

Related

I can't create an outlet for a label in my collection view cell

So everything is done the way you would assume. I drag and drop a collection view into a controller view. I connect the datasource and delegate. blah blah blah everything is done by the book.
Ok so i want to connect a label inside my collectionViewCell to my viewController class. I use control+drag to drop it into my code and type in its name.
As soon as i hit connect, i get a red octagonal error. it says: "Illegal Configuration: The hoursPerDayOutlet outlet from the monthCellViewController to the UILabel is invalid. Outlets cannot be connected to repeating content."
I need to connect this though because as each cell is created it will have a different label.
Please help me fix and use swift. All advice is appreciated. Thanks!
You can't connect items inside a UICollectionViewCell to a UIViewController, create a UICollectionViewCell subclass, make the class of the cell to the subclass and then you can connect the items inside the cell to the subclass (not the controller). I recommend you to look at more tutorials on UICollectionView.
To add to the other answer, after creating a UICollectionViewCell subclass and verifying that the class of that cell is subclassed, you have to make sure that your UIViewController that you were originally trying to connect the outlet to is a UICollectionViewDelegate subclass.
After that you should be able to successfully create an outlet for your label, etc.

TableViewController: Replace Table with Login or Error-Screen

what is best practice to display a full-screen info in a TableViewController instead of the table on certain events, e.g. a "Login Required"-Label with an ImageView and a Login-Button?
I think, adding the content in a cell and hide all other cells should work but would not be the best solution.
It should look similar to the "Cant Connect to App Store" Screen:
There should be a label and a button and the view should not be scrollable!
What I've done is to use a regular UIViewController with a UITableView and a UIView.
The UIView can contain whatever content you want to display when not displaying the table view. Then you simply hide or show the table view.
When setting up your UIViewController, you will need to make sure to indicate that it implements the UITableViewDataSource and UITableViewDelegate protocols, and set your view controller as the data source and delegate for your table view. This is pretty straightforward.

How/where do I create a table view cell subclass and set it as the class of the prototype

I have a second viewcontoller and was linked to this
Create a table view cell subclass and set it as the class of the prototype. Add the outlets to that class and connect them. Now when you configure the cell you can access the outlets.
But I do not understand where I put the subclass and how to make one.
Outlets cannot be connected to repeating content iOS The link I was sent to.
First, create the file
The same way that you create a UIViewController or UITableViewController: In your project, go to New File. Select Cocoa Touch Class under iOS. The subclass is UITableViewCell and the name is whatever name you're giving it.
Within that class, you drag your buttons, labels, etc to create your outlets.
Assign the class to the cell
Remember to assign the class name to the cell in the identity inspector:
Put it in code
You will need a slight change in your cellForRowAtIndexPath method:
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as! MyCustomCell
where "myCell" is the identifier you've given your cell in the storyboard, and obviously MyCustomCell is the new class you've created to which you are casting your cell.

Swift Collection View to Table Cell

I have a collection view that's working fine linked to a detailViewController. However I also need to link it to a CustomCell class that's used in a table. I do not know how to set the datasource or delegate and I normally do this via the GUI in storyboards.
Should I have the collectionView in the customCell class?

iOS5 Storyboard: Reuse Custom UITableViewCell in multiple UITableViewControllers

Using a dynamic, custom cell prototype that I design in, say, UITableViewController A (in Interface Builder/Storyboard), works really well with dequeuing the cell (through its identifier, cellA) and such in cellForRow... I use a custom class (UITableViewCell subclass, let's name it MyCustomCell) to link up the labels and image thumb and it works all pretty well and straight forward in my UITableViewController A.
Now I create a UITableViewController B (in Storyboard), which happens to have the exact same design/functionality for its custom cells (dynamic cells). So I switch the class of these cells to the MyCustomCell and give it a new identifier, cellB.
In UITableViewController B, I dequeue the cell in cellForRow... and use the new identifier cellB. Note: Using cellA here leads to a crash, more or less obviously.
But when the table view shows up, while running the app, the UITableViewController A works just fine, and the almost identical UITableViewController B does not work (empty cells).
In Storyboard, it looks sort of off a bit, because the custom cell is designable within the UITableViewController A but in UITableViewController B, it's just a simple, plain cell. Despite the class associated to MyCustomCell.
How would one avoid copy&pasting these cells to the other controller (and therefore heavily going back and forth between copies when making design changes) – and rather just properly re-use it?
What you are doing is correct. I don't know why its not working, it may be some problem with reloading the tableview; check with your datasource and the datasource method.
- (NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger) section
rather what you can do is: drag a
Viewcontroller
and then drag a
tableview
and make it dynamic and do the thing that you did earlier; it worked fine for me when I did so myself.
Saying the Cell is from a your custom class doesn't mean it's "designed" the same. What you really try to achieve here (and what I'm looking for) is some king of "Contained" Cell, but this is only doable with a ContainerViewController in iOS 6 I think. The other option is to use a XIB for that one Cell — that should work just as good, but then you lose the benefits of having an overview in the Storyboard.
I had a similar problem, I had created a custom cell with a uitextfield inside it. It was working well in the first tableview but not in the second. I figured out that the textfield's delegate was not connected to the custom cell. I connected the two in storyboard by making a connection from textfields delegate outlet back to the textfield.