I need to make an inner tableView and tableViewCell deque with identifier Cell2 just like it's outer tableView & tableViewCell which deque with identifier Cell. The outer is completed with its datasource and delegate, however when I'm trying to connect inner tableView and tableViewCell I don't know where to connect its delegate/datasource to.. do I make a new class that subclass from what? Please help out in SWIFT language or SWIFT2 no OBJECTIVE C Please! Thank you guys!
From your question I understand this you have put your inner table view in main tableview's cell, so you can confirm your inner tableviews data source and delegate in your outer UITableviewcell class. First drag your tableview outlet in UITableviewcell class which you made for your cell and then confirm it in awakefromnib() you can write inside awakefromnib() method like
youroutletnameofinnertableview.datasource = self
youroutletnameofinnertableview.delegate = self
I solved it.
Firstly, you will need to make IBoutlet from innerTableView to your subClass for mine is subCell which inherits from UITAbleViewCell. Than in awakeNIB -> You would put self.innerTableView.delegate = self, self.innerTableView.datasource = self, implement requirement for protocols of uitableview datasource and delegate
Related
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.
Problem Statement : I have a UIView Nib. Inside that Nib I have UICollectionView. I created Custom UICollectionViewCell and Assigned its class i.e. ServiceCollectionView Cell. I have 2 labels inside that UICollectionViewCell. Now When I try to Make an Outlet for those labels in custom class, I doesn't let me do that. I Have attached an image too. Anyone have an idea where the problem is ? Or What I am doing wrong. Any Help would be much appreciated.
Thanks
In case of adding a collection view/ table view in a UIView with separated .xib file, you should also create a separated .xib custom cell.
In your UIView Custom class, you should implement register(_:forCellWithReuseIdentifier:), for example:
// collectionView is the IBOutlet for the collection view that exists in the view .xib file
collectionView.register(UINib(nibName: "CustomCollectionViewCell", bundle: nil), forCellReuseIdentifier: "CustomCollectionViewCell")
And you will be good to go.
For some reason Xcode opens the interface (yourclass.swift (interface))and not the class. Restart Xcode and switch between automatic and manual did help me.
You create a collection View Cell nib file separately. Now you can give the outlet connection. error is not displayed.
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.
I created a custom UICollectionViewCell (let's call it MyCustomCell) using a xib (MyCustomCell.xib) and I want to create a subclass of MyCustomCell (we'll call it MyCustomCell2). The parent of MyCustomCell2 (MyCustomCell) has an IBOutlet called titleLabel. However, titleLabel for MyCustomCell2 always returns nil even after I do
self.collectionView.
registerClass(MyCustomCell2.self, forCellWithReuseIdentifier: cellIdentifier);
in viewDidLoad
and
let cell = collectionView.
dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyCustomCell2;
in cellForRowAtIndexPath
Any thoughts on what the issue is?
Firstly, when you use registerClass your outlets are not getting connected. You need to use registerNib.
Secondly, the outlets need to be connected in the xib which you are loading. If you are loading the xib of your subclass you need to connect outlets in it.
I want to use a UITableView as a single selection in my own ViewController, now I can display it but fail to fill the cell or get wrong on how to fill the cell's textlabel. Any suggestion? ...
Implement the protocols for UITableViewDataSource, UITableViewDelegate in .h or .m then connect the tableview with the first responder -datasource and -delegate in interface builder and support the protocol required classes in your .m.
For datasource it is: cellForRowAtIndexPath and numbersOfRowsInSection.
Set your cell.textlabel.text in your cellForRowAtIndexPath method.
You have to register an object as its datasource if you want to fill it.
If you also want to receive events, you also have to implement a delegate
You can embed a TableViewController in your ViewController (property) and add the TableViewControllers view to your ViewControllers view (addSubView). Creating cells goes into the TableViewController and works the same way as in the usual case.