【问题标题】:Unable to use All UITableViews after adding a subview to the UIApplication Window将子视图添加到 UIApplication 窗口后无法使用所有 UITableViews
【发布时间】:2015-04-14 04:38:21
【问题描述】:

我遇到的奇怪问题真的很令人沮丧。我为我的应用创建了一个侧边菜单栏,我使用此函数插入​​:

- (void)insertMenunOnView:(UIView*)view atPosition:(CGPoint)position
{
    _menuButton.frame = CGRectMake(position.x, position.y,     _menuButton.frame.size.width, _menuButton.frame.size.height);
  [view addSubview:_menuButton];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissMenu)];
[view addGestureRecognizer:singleTap];
view.userInteractionEnabled = true;

for (UIButton *button in _buttonList)
{
    [_backgroundMenuView addSubview:button];
}


_backgroundMenuView.frame = CGRectMake(view.frame.size.width, 0, 150, view.frame.size.height);
_backgroundMenuView.backgroundColor =   [UIColor colorWithRed:0.09 green:0.15 blue:0.18 alpha:0.7f];

[view addSubview:_backgroundMenuView];
}

这里是在我的UITableViewControllerviewDidAppear方法中实现的:

override func viewDidAppear(animated: Bool) {
    sideBar.insertMenuOnView(self.view, atPosition: CGPointMake(100, 200))
}

如果我这样做,它会使我的TableView 无用。如果我在多个单元格之间来回快速点击,我可以选择单元格。这样做大约十秒钟后,被点击的单元格将启动适当的 segue。

不,我尝试过这个,希望能够通过将函数更改为来解决这个问题

 - (void)insertMenunOnView:(UIWindow*)view atPosition:(CGPoint)position
{ //// do stuff
}

你猜怎么着!?现在,我整个应用程序中的每个tableView 的行为都与第一个相同!大约需要三十到四十次点击,直到单元格最终调用didSelectRowAtIndexPath

到底发生了什么?

【问题讨论】:

    标签: ios objective-c uitableview swift uiview


    【解决方案1】:

    关闭侧边菜单时禁用视图上的点击手势,打开侧边菜单时启用它。

    目前您的点击手势正在覆盖表格视图的点击手势。

    【讨论】:

      【解决方案2】:

      问题是-

      当您拨打sideBar.insertMenuOnView(self.view, atPosition: CGPointMake(100, 200))时

      这个方法被调用

      - (void)insertMenunOnView:(UIView*)view atPosition:(CGPoint)position
      inside your dismissMenu event handler you should remove gesture recognizer
      

      在上面的方法中,您正在当前视图上添加手势识别器,当您完成此视图时,您将关闭它,但点击手势仍然存在并添加到当前视图上。现在,当您尝试选择表格的任何行时,触摸不会传递到表格,因为它被上面的图层拦截(当然是在当前视图上添加的点击手势识别器。)

      要解决这个问题,您应该从您的dismissMenu 方法中的当前视图中删除轻击手势识别器。这样做会将您的触摸传递到 tableView 的相应行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多