0

我想创建一个从视图一侧滑动的菜单,因此我以编程方式创建了一个 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;

}
4

3 回答 3

2

我也遇到了这个问题,我也没有发现。

我正在使用NIDropDown自定义控件 tableview 显示,但我无法选择或滚动。问题是当我这样做时[anySuperView addSubview:anyTableView];

anySuperView的尺码 (75) 小于我anyTableView的尺码 (400)。所以我做了superViews尺寸(500),我的问题解决了。

任何可以提供更多技术细节的机构将不胜感激。

这么晚才回答这个问题,因为我在其他任何地方都找不到解决方案

于 2014-03-28T15:23:19.757 回答
1

我不太确定你在找什么。但是如果您希望单元格在选中时突出显示,则需要将这行代码添加到您的 tableView 中: cellForRowAtIndexPath:

yourcell.selectionstyle = UITableViewSelectionStyleBlue

你也可以使用 UITableViewSelectionStyleGray。如果你想在他们选择行时执行一些操作,你可以使用 tableviewdelegate 方法:

管理选择

– tableView:willSelectRowAtIndexPath:

– 表视图:didSelectRowAtIndexPath:

– tableView:willDeselectRowAtIndexPath:

– tableView:didDeselectRowAtIndexPath:

UITableViews 可能很棘手,但可以在 Apple 的参考资料中轻松找到类似的内容:

http://developer.apple.com/library/ios/navigation/

只需搜索班级或代表或您正在使用的任何内容。

于 2012-09-17T10:04:35.700 回答
0

它有一个类似的问题。我通过将我的表格视图添加到更远的位置并设置一个标志来跟踪它是否已安装来解决它。在您的代码中,移动 [paintView addSubview:tablaConfig]; 进入 btnTablaConfig: 方法,在第一次展开表时执行它。该问题似乎涉及查看初始化代码时间。

于 2012-11-02T23:34:07.487 回答