jeudi 25 juin 2015

When I add UITableView to subview, the cells aren't selectable

I have a custom class that is a subclass of UIView. I added a UITextField and a tableview as a subview. Then, in the storyboard, I set a UIView's class to the custom class.

The tableview I added in the custom class, extends larger than the initial UIView, (from the storyboard). So I changed self.frame's height.

When I run the app, I can type in the textField I added, but I can't select anything in the tableview. I can see the cells, but can't select them.

How can I make the cells selectable?

Here is the most relevant code:

_textField = [[UITextField alloc] initWithFrame:self.bounds];
[self addSubview:_textField];

CGRect tableViewsFrame = self.textField.bounds;
tableViewsFrame.origin.y += self.textField.bounds.size.height;
tableViewsFrame.size.height = 200;

_tableView = [[UITableView alloc] initWithFrame:tableViewsFrame style:UITableViewStylePlain];
[self addSubview:_tableView];

CGRect viewsFrame = self.bounds;
viewsFrame.size.height = self.textField.frame.size.height + self.tableView.frame.size.height + 100;
[self setFrame:viewsFrame];

Here is a link to a test project on jumpshare: testProject

See more ..

Aucun commentaire:

Enregistrer un commentaire