我一直在StackOverflow很多不同的问题,但我只是无法弄清楚这里有什么问题。 我有一个视图控制器,从JSON接收数据,创建一个数组,然后,它建立一个具有固定高度的UITableView。 问题是我无法滚动到底部。它只是反弹回来。UITableView滚动返回顶部
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"SettingsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
[cell.detailTextLabel setNumberOfLines:2];
NSDictionary* place = [_placesData objectAtIndex:indexPath.row];
[cell.textLabel setText:[place valueForKey:@"nome"]];
[cell.detailTextLabel setText:[place valueForKey:@"endereco"]];
[cell.detailTextLabel setLineBreakMode:NSLineBreakByWordWrapping];
[cell.detailTextLabel sizeToFit];
UIImage* originalImage = [UIImage imageNamed:@"encontre.png"];
UIImage* resized = [UIImage imageWithCGImage:[originalImage CGImage]scale:(originalImage.scale * 1.8) orientation:(originalImage.imageOrientation)];
cell.imageView.image=resized;
cell.textLabel.font = [UIFont fontWithName:@"GillSans" size:17];
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.font = [UIFont fontWithName:@"GillSans-Light" size:17];
self.tableView.scrollEnabled=YES;
self.tableView.bounces=YES;
[self.tableView setAlwaysBounceVertical:YES];
return cell;
}
我不知道该怎么办。已尝试手动设置contentSize.height
,强制bounces
和scrollEnabled
几乎将视图控制器上的一段代码翻转过来。
问候。
那些最后三行之前'return'(设置滚动和弹跳行为的那些)不属于这种方法。最好把它们放在你的'UITableViewController'子类的'init'方法中,因为这些属性只需要设置一次。 – bdesham
假设您正在使用界面生成器来处理主布局?所有这些自动调整属性都设置正确吗?除了@ bdesham的评论(这仍然不会导致您所看到的问题),此方法中的任何内容都不会显得太糟糕。 – jterry
当然看起来像那个tableview框架正在可见的视图下方。 (比你看到的要大得多)你可以启用侧滚动条吗?当你滚动(拉起来)时,你会看到侧滚动条移动到可见的tableview框架之外 - 这意味着框架太大了。你有任何scrollViewDidScroll委托方法?另一种选择是填充tableview,比如100条记录。然后看看它是否允许滚动并且不反弹。 –