【问题标题】:Scroll to the last two rows of table滚动到表格的最后两行
【发布时间】:2014-12-17 15:32:53
【问题描述】:

当表格的记录多于屏幕让您看到的记录,并且用户滚动到底部以查看表格中的最后一条记录时,最后两行无法访问(仅在 iOS7 中,在 iOS8 中一切都很好)。一旦用户将手指从屏幕上移开,表格就会上升,最后两行被隐藏。

这是用于 tableView 的方法之一,但我不知道这是否来自这里:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *  cellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

// Configure the cell...
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

if (selectionCategMsg == 0)
{
    if ([self.tableauMsgReceived count] < 1) {
        cell.textLabel.text = NSLocalizedString(@"noMessagesYet", nil); //@"No messages yet !";
    }

    else
    {
        cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.tableauMsgReceived objectAtIndex:indexPath.row]];
        cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    }
}

else
{
    if ([self.tableauMsgSent count] < 1) {
        cell.textLabel.text = NSLocalizedString(@"noReplyYet", nil);
    }

    else
    {
        cell.textLabel.text = [NSString stringWithUTF8String:[NSString stringWithFormat:@"%@", [self.tableauMsgSent objectAtIndex:indexPath.row]].UTF8String];
        cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    }
}

[cell setAccessoryType:UITableViewCellAccessoryNone];

return cell;
}

有人可以给个建议吗?谢谢你。

这是我找到的解决方案:

// -> SET TABLE FRAME
CGFloat sideMargin = 0;
CGFloat originX = sideMargin;

CGFloat topBottomMargin = 100;
CGFloat originY = topBottomMargin;

// Width based on view size
CGFloat sizeWidth = self.view.bounds.size.width);

// Height based on view size
CGFloat sizeHeight = (self.view.bounds.size.height - topBottomMargin);

self.myTableView.frame = CGRectMake(originX, originY, sizeWidth, sizeHeight);
// <- END SET tableView frame

【问题讨论】:

  • tableView 有错误的边界并超出屏幕...视图有错误的框架。显示您创建表和/或 xib 的代码
  • 并删除所有不相关的代码

标签: ios objective-c xcode


【解决方案1】:

UITableView 有方法scrollToRowAtIndexPath:atScrollPosition:animated:。该方法允许您滚动表格视图,以便给定的 indexPath 可见。这就是你要找的吗?

编辑:

@Daij-Djan 的帖子很好地说明了问题所在。如果您的表格视图离开屏幕,那么它将在其视图中定位最后几个单元格,但该视图将不可见。您将需要进行一些调试以找出问题所在。您可以尝试将 table view 的 layer 的 borderWidth 设置为非零值,以便查看 table view 的边界。

在您的 viewDidLoad 中,添加如下代码:

myTableView.layer.borderWidth = 1;
myTableView.layer.borderColor= [UIColor redColor].CGColor;

(您可以将“myTableView”替换为表格视图实例变量或属性的名称。)

您必须导入 QuartzCore.h 才能编译上述代码:

#import <QuartzCore/QuartzCore.h>

【讨论】:

  • 然后发布您的代码。我用过那个方法,效果很好。
  • @Developer3000 ??????我投票结束这个......你说你尝试了一些你甚至不知道它在哪里的东西:D
  • 当我写下“我已经尝试过”时,就是这个意思。显然你的回复不会帮助任何人。除非您对发布的问题有答案,否则请尽量为自己保留此类 cmets。
  • @Duncan 谢谢,我使用了你的代码,我可以看到左右和顶部的边框,但看不到底部
  • 对于感兴趣的人,我修改了我的问题,添加了我找到的解决方案。 @Duncan:感谢回复我
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-21
  • 1970-01-01
  • 2017-11-07
  • 2012-05-24
相关资源
最近更新 更多