简体   繁体   English

UITableView粘在iOS8中

[英]UITableView sticking in iOS8

I have a UITableView in an app that you can use your finger to scroll up and down. 我在一个应用程序中有一个UITableView ,您可以用手指上下滚动。 Users who have updated to iOS8 who tell me it is now sticking and it does not scroll up or down. 更新到iOS8用户告诉我它现在一直iOS8并且它不会向上或向下滚动。 It appears to be random. 它似乎是随机的。 Sometimes it works, other times it does not. 有时它起作用,而其他时候则不起作用。 By moving to a different view and returning sometimes unlocks it. 通过移动到其他视图并有时返回可以解除锁定。

The UITableView is populated with an array of UIButtons (one example shown below). UITableView填充有一组UIButtons (下面显示一个示例)。 It works perfectly in iOS7. 它在iOS7中完美运行。 Is there something that has changed min iOS8 that I am unaware of? iOS 8最低版本有什么我不知道的更改吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
if (cell ==nil)
{
    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

/* this is man example of a button being established. / *这是建立按钮的示例。 5 buttons are actually made*/ 实际制作了5个按钮* /

UIButton* button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 setFrame:CGRectMake(0,0,160, 160)];
[button1 setBackgroundImage:[UIImage imageNamed:@"Button1.png"] forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1] forState:UIControlStateNormal];
button1.titleLabel.font = [UIFont fontWithName:@"arial" size:24];
button1.titleLabel.textAlignment = NSTextAlignmentCenter;
button1.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
[button1 addTarget:self action:@selector(action1:) forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:@"Menu" forState:UIControlStateNormal];

/* the buttons are stored into an array*/

NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:button1];
/*other buttons added to the array*/


[cell addSubview:[array objectAtIndex:indexPath.row]];

return cell;

There are 2 possible things: 有两种可能:

  • Better to use cell.contentView to add subviews 最好使用cell.contentView添加子视图
  • You always add subviews to the existing cells without removing the previous added 您始终将子视图添加到现有单元格,而不删除先前添加的子视图

UIButton s in scroll views can cause issues with scrolling. 滚动视图中的UIButton可能导致滚动问题。

Try tableView.canCancelContentTouches = YES; 尝试tableView.canCancelContentTouches = YES;

If that doesn't help try to additionally subclass UITableView , overwrite touchesShouldCancelInContentView: and return YES there. 如果这样做没有帮助,请尝试另外子类化UITableView ,覆盖touchesShouldCancelInContentView:并在那里返回YES

Try using TapGesture instead of button. 尝试使用TapGesture代替button。 I met the same problem and finally TapGesture solved the problem. 我遇到了同样的问题,最后TapGesture解决了这个问题。

In iOS8,when you put a button on a cell,if the button is not big enough and you try to scroll the tableView while your finger is within the area of the button,the tableView will simply not scroll. 在iOS8中,当您在单元格上放置一个按钮时,如果该按钮不够大,并且您尝试在手指位于按钮区域内时滚动tableView,则tableView根本不会滚动。 PS: You can try make the button smaller,and drag outside of the button,you will find it scrolls just as you wish. PS:您可以尝试将按钮变小,然后将其拖动到按钮外,您会发现它可以随意滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM