last day (14 days later) » 

7:04 PM
0
Q: Swift Calling method from deeply nested UIView

JamesI'm getting really confused about calling methods on a dynamically added subview. I know I'm making a newbie mistake but I just can't figure it out. My hierarchy looks something like this: TableView - TableViewCell - CustomContainer (UIVIew subclass) - Widget (UIVie...

 
In your hierarchy you mention that you use a UITableView, are you using Dynamic Prototype Cells or Static Cells?
 
@Dershowitz123 thanks - I tried that and I get the same error.
@Dilts Prototype cells
 
@James is your button IBAction in the UITableView class or in your UITableViewCell class?
 
@Dilts in the Widget class :-p
 
@James You're getting [myApp.CustomContainer myButtonTapped:]: unrecognized selector sent to instance, so your button is trying to call the myButtonTapped selector from the CustomContainter class, but it should be in your widget class, as you said. Check to see if your IBAction is hooked up correctly to the right class and if your UIButton is actually in the widget view hierarchy.
 
7:04 PM
@Dilts My thinking was that the CustomContainer can have multiple Widgets, each with it's own methods that don't need to interact with any siblings. Keeping the methods with the Widget seemed the most logic place for them.
@Dilts Thanks for the suggestion - "your UIButton is actually in the widget view hierarchy" how would you do this?
 
@James I'll post a answer to your question with a few photos of what it should look like.
 
@Dilts thanks - my project is pretty complicated and I think I've got myself in a real mess. Will try your suggestions but perhaps it's time to delete some stuff :-)
 
I'll post my answer in a bit. I've been through this plenty of times before!
 
haha - thanks...I'm glad someone else knows what it's like :-)
 
7:33 PM
Pronto! A suggestion might be to just add the button directly to you custom UITableViewCell, that way you don't have to handle the pesky #selector() to get your button working.
 
Thanks Dilts - I'm just looking at your answer. The comment about refactoring is valid (and I certainly agree!) but all the views are added dynamically depending on what type of cell is required and then what's needed in each cell changes...it's a bit of a nightmare!
BTW Refactoring Swift in Xcode isn't as easy as it might be :-/
I'm going to grab some food now and give my brain a rest...I'll be back later with some upvotes and any progress reports. Thanks so much for your help.
 

last day (14 days later) »