Reputation: 3831
I want to create a menu that appears sliding from a side of my view, so I programmatically created a UIView and a UITableView, but, when it appears I can't select the cells in my view, here's the code where I created the view and the table:
paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 400)];
[paintView setBackgroundColor:[UIColor clearColor]];
tablaConfig = [[UITableView alloc]initWithFrame:CGRectMake(-160, 0, 160, 400) style:UITableViewStylePlain];
tablaConfig.delegate = self;
tablaConfig.dataSource = self;
tablaConfig.userInteractionEnabled = YES;
tablaConfig.scrollEnabled = NO;
tablaConfig.backgroundColor = [UIColor lightGrayColor];
[paintView addSubview:tablaConfig];
And here's the code where I make the table appear and disappear:
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
if (self.view.frame.origin.x == 0) {
//[self.view addSubview:paintView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
// Move right.
rect.origin.x += 160;
rect.size.width -= 160;
self.view.frame = rect;
[UIView commitAnimations];
selector = false;
tablaConfig.userInteractionEnabled = YES;
}
}
else {
if (self.view.frame.origin.x == 160) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5]; // if you want to slide up the view
CGRect rect = self.view.frame;
rect.origin.x -= 160;
rect.size.width += 160;
self.view.frame = rect;
[UIView commitAnimations];
selector = true;
tablaConfig.userInteractionEnabled = NO;
}
//[paintView removeFromSuperview];
}
}
Hope you can help
EDIT:
When I use this, I can select the cells, but lose the sliding effect, how can I get both?
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
[self.view addSubview:tablaConfig];
selector = false;
}
else {
[tablaConfig removeFromSuperview];
selector = true;
}
Upvotes: 0
Views: 6283
Reputation: 1016
I also got this problem and I also didn't found that.
I am using NIDropDown
custom control tableview shows but i cant select or scroll.
problem was that when I do [anySuperView addSubview:anyTableView];
My anySuperView
's size (75) was less than my anyTableView
's size (400).
so I made superViews
size (500) and my problem solved.
Any body who can give more technical detail about this will be appreciated.
So late answering this because I found no solution anywhere else
Upvotes: 2
Reputation: 2530
It had a similar problem. I solved it by adding my table view farther down down the line and setting up a flag to keep track if it was installed. In your code, move [paintView addSubview:tablaConfig]; into the btnTablaConfig: method, executing it the first time the table is expanded. The problem seems to involve view init code timings.
Upvotes: 0
Reputation: 315
I'm not quite sure what you're looking for. But if you want the cell to be highlighted when selected, you need to add this line of code to your tableView: cellForRowAtIndexPath:
yourcell.selectionstyle = UITableViewSelectionStyleBlue
You can also use UITableViewSelectionStyleGray. If you want to perform some actions when they select the row, you can use the tableviewdelegate methods:
Managing Selections
– tableView:willSelectRowAtIndexPath:
– tableView:didSelectRowAtIndexPath:
– tableView:willDeselectRowAtIndexPath:
– tableView:didDeselectRowAtIndexPath:
UITableViews can be tricky but stuff like this can be easily found in Apples references at:
http://developer.apple.com/library/ios/navigation/
Just Search for the class or delegate or whatever you are using.
Upvotes: 1