Button inside Cell Table View Swift iOS - ios

I have a custom cell with a button.
When I implement the outlet get me a error.
This is a screen :

It looks like you're trying to add the IBOutlet to the view controller instead of inside the cell.. You need a UITableViewCell class and add there the IBOutlet. I also recommend you to use a verbe for the IBActions method names.

Check this out, if you didn't create a custom UITableViewCell class.
https://www.youtube.com/watch?v=JG_AMY_gSDQ

Related

How to add a button in the TableviewController?

I was wondering how to add a simple static button at the bottom right of the Tableviewcontroller background, its will be contact infos.
I have tried through through the storyboard with no success.Do you have any clue for that?
Thank you ,
Regards,
Take ViewController and Add TableView inside it.
Take one View and set the bottom of the view controller and set button inside that View.
I would suggest you to make a normal ViewController, add a tableView and save an space for that button, take note that you have to set the delegates and datasource for that tableview.
You could use footerView if you want this button to appear only at the bottom of the whole TableViewController. To do that, you can drag a view after the cell in the hierarchy:
If you really want to use a UITableViewController, you could create a normal UIViewController, add a container in it and embed a UITableViewController in the container. Here's an example:
Create a UIView with UIButton and set this view as TableView's FooterView

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.

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.

Can't assign custom UITableViewCell within custom UIViewController

In my storyboard, if I have a UIViewController that inherits from a custom class, can I create a custom class for a UITableViewCell within a tableview inside that UIViewController?
I've tried to do the above, but when I try to connect outlets, I can only drag to the parent ViewController file, and not to the connected TableViewCell file. Why is that?
You can connect outlets of your cell.
You need to assign the class of custom table view cell in storyboard.
Select the table view cell while dragging to connect outlets.
You seem to be asking 2 questions:
"can I create a custom class for a UITableViewCell"?
Yes, you can use a custom class for your UITableViewCell. Simply select the cell and in the class inspector, enter the custom class.
"I can only drag to the parent ViewController"
That's also correct. For static cells, you can link them to outlets in the view controller. Note that for dynamic cells, you'll need to create them in the tableView:cellForRowAtIndexPath: method.

UICollectionViewCell not detecting touches

I've tried adding a UIButton to the cell's contentView, which wasn't getting called. Then I tried adding a touchesBegan method to the cell. It's not being called. The cell has it's background color being set, and I can see in the extrapolated view that XCode now provides that it's the topmost view.
Any thoughts as to why interaction might not be working?
I think answer lies into UICollectionView delegate methods and datasource, you don't need touchedBegun etc,
I guess you want to know which cell has been tapped. More codes will definitely helps.
In storyboard do this,
A viewController with UICollectionViewCell inside it.
Add UIViewController subclass in your project and make your storyboards viewController as its subclass.
Add UICollectionView subclass and make your UICollectionViewCell its subclass.
read upon this link http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

Resources