Reputation: 503
There is a custom view that I extend from UITableViewCell.
In CustomTableViewCell, I implement init method so that it loads a corresponding .xib which contains button.
However, I want to reuse it as if it's a normal UIView instance. For instance, I want add it as a child of my view controller
// in view controller
CustomTableViewCell* customTableViewCell = [[CustomTableViewCell alloc] init];
[self.view addSubview:customTableViewCell];
The problem is, the custom table view cell can be added, but the button that it holds can not be pressed. Meanwhile, the button of the custom table view cell that is populated by table view is working fine.
In the screenshot above, the button with the yellow highlight can not be pressed, while the blue can.
Anyone has the idea why it's not working?
Upvotes: 0
Views: 66
Reputation: 4586
May be you need pass fileowner in 'init' method, if you have assigned button's actions to fileowner in xib-file.
Upvotes: 0
Reputation: 62686
It's a guess, but you create the cell with a CGRectZero frame. It doesn't clip it's subviews so they can still be seen, but it's subviews won't get touches outside of the superview's bounds (which are zero). Try alloc initWithFrame:CGRect(/* some reasonable values */)
.
Once you get that working, you can try with some layout constraints.
Upvotes: 2