Warut Surapat
Warut Surapat

Reputation: 503

Button is disabled when using UITableViewCell instance as if it was a UIView instance

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.

https://www.evernote.com/shard/s27/sh/59f7b828-f65a-41dc-9156-40a985fceac8/9edb04b8e5c821ad7a46eb714cc776dc

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

Answers (2)

Cy-4AH
Cy-4AH

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

danh
danh

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

Related Questions