I don't know why Xcode won't allow you to drag from your label to the bottom view .h file, but you can do it another way. Add the IBOutlet property to the .h file, then drag from the littler open circle to the left of the @property to your label in the storyboard, and that should work.
Wire components to the custom view inside a UITableViewCell
-
14-07-2023 - |
Question
Came up this question and did some quick experiments without no luck.
Basically, I made a simple single view project where the top view controller is a UITableViewController
. For simplicity, I set the table view content to be "Static Cells". The table cell was a custom subclass of UITableViewCell
, like this
@interface TopTableViewCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet TableCellBottomView *bottomView;
@end
Both the properties were wired through control dragging. The TableCellBottomView
is just a custom subclass of UIView like this
@interface TableCellBottomView : UIView
@end
Now I add a label inside this TableCellBottomView
like the following picture showing
Can I wire this bottom label
inside to my TableCellBottomView
? Control dragging did not work for me here. I certainly could have added it programmatically inside TableCellBottomView.m
. But if i could wire it here, it would be quite convenient, since I could also add a lot of other components and arrange them visually. Thanks!
Solution 2
OTHER TIPS
You may set a tag for the label in Xcode and fetch the UILabel based on the tag wherever you need it:
If you use dynamic cells, you can do this in tableView:cellForRowAtIndexPath:. Alternatively wire the cell to a property and then use that property to fetch it:
((UILabel*)[cell viewWithTag:1]).text = @"Some text";