我想创建一个从我的视图侧面滑动的菜单,所以我以编程方式创建了一个UIView和一个UITableView,但是,当它出现时我无法在我的视图中选择单元格,这里是我的代码创建了视图和表格:
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];
这是我让表格显示并消失的代码:
- (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];
}
}
希望你能帮忙
修改:
当我使用它时,我可以选择细胞,但是失去滑动效果,我怎样才能同时获得它们?
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
[self.view addSubview:tablaConfig];
selector = false;
}
else {
[tablaConfig removeFromSuperview];
selector = true;
}
答案 0 :(得分:2)
我也遇到了这个问题,我也没有找到。
我正在使用NIDropDown
自定义控制tableview节目,但我无法选择或滚动。
问题在于我做[anySuperView addSubview:anyTableView];
我的anySuperView
的大小(75)小于anyTableView
的大小(400)。
所以我做了superViews
尺寸(500),我的问题解决了。
任何能够提供更多技术细节的机构都将不胜感激。
这么晚回答这个问题是因为我在其他地方找不到任何解决方案
答案 1 :(得分:1)
我不太确定你在寻找什么。但是如果你想在选择时突出显示单元格,你需要将这行代码添加到tableView:cellForRowAtIndexPath:
yourcell.selectionstyle = UITableViewSelectionStyleBlue
您还可以使用UITableViewSelectionStyleGray。如果要在选择行时执行某些操作,可以使用tableviewdelegate方法:
管理选择
- tableView:willSelectRowAtIndexPath:
- tableView:didSelectRowAtIndexPath:
- tableView:willDeselectRowAtIndexPath:
- tableView:didDeselectRowAtIndexPath:
UITableViews可能很棘手,但是这样的东西可以在Apples参考资料中轻松找到:
http://developer.apple.com/library/ios/navigation/
只搜索班级或代表或您正在使用的任何内容。
答案 2 :(得分:0)
它有类似的问题。我解决了这个问题,方法是将我的桌面视图添加到线下并设置一个标记以跟踪它是否已安装。在你的代码中,移动[paintView addSubview:tablaConfig];进入btnTablaConfig:方法,在第一次扩展表时执行它。问题似乎涉及查看初始化代码时间。