UITableView inside UITableViewCell using Interface Buillder - ios

I have an tableView called BasicTable that have custom cell called CustomCell and I want to add a new table view inside this CustomCell.
I have an BasicTableView.m for BasicTable and CustomCell.m for CustomCell and add the new table view using Interface Builder but now don't know where to go or where to add reference to the new tableView and it's new cell.

You can create a reference to the new tableView directly in CustomCell.m (e.g. by setting it as a property) and set the cell itself als dataSource and delegate of the tableView.
Having another tableView inside of a table view cell however doesn't seem like a good design decision, this will lead to problems in UX (e.g. concerning the scrolling of the two). Did you consider using sections inside the table view instead?
Also, if you use my above solution (which I wouldn't recommend because of the UX issues), be sure to update the tableView inside the table view cell, this should best be done in the table view cell's method prepareForReuse, it could look like this:
- (void)prepareForReuse
{
[super prepareForReuse];
[self.tableView reloadData];
}
And do this only after having updated the cell in the table view controller in cellForRowAtIndexPath:

You should connect your new tableview to your CustomCell and set it as datasource and delegate, and implement that protocols in you CustomCell.
i.e. your BasicTable controls by your ViewController, but new tableview controls by CustomCell.

Related

UITableViewCell into multiple View Controllers

I started to develop an app that use two view controllers (VCs). For each VCs I use a uitableview that use the same uitableviewcell. My ask is if exist a same queue between uitableview where to use a uitableviewcell between two view controllers or if i should create a custom queue where i can to reuse the contentview of uitableviewcell
More graph
VC1 - UITableView1 -> UITableViewCell1
VC2 - UITableView2 -> UITableViewCell1
I would like to reuse the UITableViewCell1 in both tables and decrease the use of memory.
pd: the navigation between these vcs is with a uinavigationcontroller.
Thx
Yes. You can do it by creating Custom Table View Cell and Use it in all table views.
I'd added solution for the same kind of issue on Collection View.
You just refer the same for your Tableview. You just repeat the same with Tableview cell.
Common Collection View Cell in all collection Views
Hope it helps.

How to open new ViewController after click(touch) on ImageView?

I have TableViewController with a custom cells.
For table is responsible class:
#interface CustomTableViewController : UITableViewController
For cells is responsible class:
#interface CustomTableViewCell : UITableViewCell
The ImageView are located in cell of table.
How I can open new controller when I click(touch) at ImageView inside cells?
As it appears I must to use UIViewController near UITableViewCell that to open new viewController, is not?
Usually this kind of stuff is handled inside UITableViewDelegate method didSelectRowAtIndexPath. However the table view calls this method when the entire cell is tapped.
If you want to trigger the action only for the image, you might have to add UITapGesture to the image view. Do not forget that image views have userInteractionEnabled set to false by default. There are two ways to communicate the tap event to the view controller that i can think of right now. Either by delegation or closure. The latter one requires less code.

UITableView - how to register a cell from secondary view?

If you drag a UITableViewCell onto the top toolbar of a view controller, it appears above the view controller in IB as a secondary view. This is nice because you can do all the layout there. But how do you then get a table view to load the cell from there?
This doesn't work:
[self.tableView registerClass:[MyCustomTableViewCell class] forCellReuseIdentifier:#"MyCell"];
And since it's not in a separate nib file, registerNib doesn't seem appropriate either. Any ideas?
Although that may be possible you have several options when designing tableview cells. You can either design it in a separate .xib file or you can use a prototype cell. Below is an example of a separate .xib file. When you use a separate .xib you would use the registerNib method.
Or with a prototype cell in which the cell is automatically registered with the tableView.

Swift - Outlets cannot be connected to repeating content

The full error is: The playerView outlet from the TableViewController to the AVPlayerView is invalid. Outlets cannot be connected to repeating content.
Similar answers like this one have not worked (assuming I am attempting them correctly, I'm very new to iOS).
All I want is a view within a TableViewCell.
I've tried dragging a View in Storyboard to the contentView (and cell) of my TableViewCell, assigning it a class of AVPlayerView: UIView (and a subclass of tableViewCell: AVPlayerView: UITableViewCell), then ctrl+dragging from that view in the storyboard into my TableViewController. Then it doesn't compile. Really confused, thanks for the help.
Your table view can have static content or dynamic content.
If you want the table view to have always the same content, set it to static (in interface builder), and then you can link the outlets like that, in the UIViewController.
If you want the table view cells to change dynamically, you cannot do it that way. Because you could repeat cells and the outlet would be ambiguous. You need to create a UITableViewCell subclass for your cells, and create the outlets there.
To clarify: in dynamic table mode, you need to ctrl+drag the outlet into the UITableViewCell subclass, not the view controller.
Very simple solution is:
Just take the view or NSLayoutConstraint reference outlets in the subclass of table view cell instead of table view controller and access using object of table view cell in cellForRowAtIndexPath method or any other method.

UITableView in a View controller by a UIViewController and not a UITableView

I have a View with lots of things inside it including buttons, a scroll view and a tableView (ipad app). I am controller this view with a viewController subclass but I don't know how to manage my tableView. I don't know where put the methods :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
should I add them to my ViewController or should I create a new subclass of UITableViewController (and get them "for free") and set the dataSource and delegate of my tableView to that class when I create it programmatically?
I am storing the data I want to show in my appDelegate
.
You just have to set the UIViewController as the delegate and dataSource of your UITableView. That's it. You don't need to create a own subclass of UITableViewController for managing that tableView. So you can put all the subviews in the viewController's view.
Thank you so much, I got it. I was trying to create a tableView and then set it's datasource. In fact the easier way is to create a tableViewController and use it's .view property that is already linked to it and use the addSubview method to put it in the main viewController's view.
Cheers

Resources