Reputation: 933
I am using this open source framework in swift https://github.com/uacaps/PageMenu for my view controller.
I am using xib for the tableview cells and the tableview as shown in the demo projects.
However, when I go to connect my buttons from the tableview cell to the table view controller Xcode will not let me. I am working on the NotificationTableViewCell and NotificationTableVC files.
I have set up the project properly and can get the cell up and running as well as the project itself. However if I can't get the buttons to connect I cannot add the needed functionality.
The demo projects also have this behaviour when I cloned some from the repository. I looked through the issues and no one seemed to mention anything about connecting IBActions to the view, so I did, but I assume there is something I am missing.
I have attached screen shots to help you see my issue. I need to access the cellForRowIndexPath as well.
My xib is given the class of my table view cell which still wont allow me to interact with the tableview controller.
Upvotes: 0
Views: 702
Reputation: 933
Okay, so I have figured out a working solution. Thanks to Gurtej Singh.
Here is the code:
1) I added this line in the cellForRowIndexPath
cell.mybutton.addTarget(self, action: "declineRequest:", forControlEvents: .TouchUpInside)
2) Now I am able to access the button if I write a function called declineRequest
Since I want to delete the cell based on its data I use this function and add the Parse query logic.
func declineRequest(sender: UIButton) {
var cell: NotificationsTableViewCell = sender.superview!.superview as! NotificationsTableViewCell
.... }
Upvotes: 2
Reputation: 3234
I don't think you will be able to connect a table view cell element to a table view controller class via IB (and from what I know, it's not correct to do so as well, because there will be multiple cells and re-usability).
Connect the element from the IB to your Cell class (.h/.m), create one if you don't have it , like NotificationTableViewCell.m, and then access the connected element from the delegate methods inside your Table View controller class.
Hope this helps.
Upvotes: 1