UITutView滚动后UIButton无法点击

时间:2012-11-27 19:01:30

标签: objective-c ios uitableview uibutton

我有一个UITableView,其中填充了一些单元格。我使用以下代码段创建了一个UIButton,它放在一个节标题旁边。

UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton addTarget:self action:@selector(addButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[addButton setBackgroundImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
addButton.backgroundColor = [UIColor clearColor];
addButton.frame = CGRectMake(270, 150, 29, 29);

按钮已放置并正常工作。但是,在滚动视图(甚至稍微 - 像1个像素)后,按钮会工作一次,然后停止响应。当它没有响应时,单击它的动作没有被触发,按钮不会给出“凹陷”的阴影。应用程序的其余部分正常运行,不会崩溃。

这看起来很奇怪,因为滚动按钮后再次点击它再停止工作。该按钮用于将行插入表中,因此在按下之后会有一个额外的行,这可能会破坏边界或什么?

按钮按下功能:

- (void)addButtonPressed {
    self.addClientTable.editing = YES;

    // First figure out how many sections there are
    NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.addClientTable] - 1;

    // Then grab the number of rows in the last section
    NSInteger lastRowIndex = [self.addClientTable numberOfRowsInSection:lastSectionIndex];

    [self.addClientTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex]] withRowAnimation:UITableViewRowAnimationRight];

    self.addClientTable.editing = NO;
}

addClientTable是UITableView。

什么可能导致UIButton停止响应点击以及我的方案中的哪个位置会导致?

1 个答案:

答案 0 :(得分:3)

我几乎可以确定您的问题是您的按钮超出了超级视图,并且您没有在视图中使用包含按钮的剪辑子视图选项,或者在其中一个超级视图中使用。

将所有视图属性剪辑子视图设置为true,并查看它是否显示在您的按钮上。 (我们希望按钮消失)

如果您提供更多代码,我可以尝试帮助您解决此问题。

-

再次阅读你的问题,另一个可能的问题是你的按钮前面有一个视图。您可以测试它来改变视图的背景,或类似的东西。