【问题标题】:Strange Tableview scrolling behavior奇怪的 Tableview 滚动行为
【发布时间】:2014-02-14 00:10:17
【问题描述】:

我有两个视图,每个视图都包含一个表格视图。除了高度之外,它们在所有方面都是相同的。它们各自从我的 Core Data 存储中的同一个实体(目前充满了乱码)中获取数据。

其中一个在滚动时完美运行,另一个表现不同。问题是单元格滚动过顶部部分标题。后续的部分标题按预期将较旧的部分标题向上提升,并且标题标题与单元格一起向上滑动。

以下是几张截图,希望能说明问题:

首先,正常工作的那个:

“A”是顶部的部分标题,单元格不会滚动过去。

接下来的两个镜头是行为怪异的 tableview。我添加了一些箭头来显示正在发生的事情:

我比较了属性检查器中的设置,除非我忽略了某些内容,否则它们看起来是相同的。

有人有什么想法吗?

谢谢!

编辑:

这是来自关联 UIViewController 的代码,它是 TableView 的委托和数据源:

//
//  AvsAViewController.m
//  WMDGx
//
//  Created by Tim Jones on 2/6/14.
//  Copyright (c) 2014 TDJ. All rights reserved.
//

#import "AvsAViewController.h"

@interface AvsAViewController ()
{
    NSFetchedResultsController *frc;
}

@end

@implementation AvsAViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self refreshData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[frc sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id<NSFetchedResultsSectionInfo> sectionInfo = [[frc sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

// Customize the appearance of table view cells.
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    // Configure the cell to show the activity's name
    ListActivity *thisActivity = [frc objectAtIndexPath:indexPath];
    cell.textLabel.text = thisActivity.activityName;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"aVSaCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    [self configureCell:cell atIndexPath:indexPath];

    cell.textLabel.textColor = [UIColor redColor];
    NSAttributedString *attString;
    attString = cell.textLabel.attributedText;
    return cell;
}


//     Section Label

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *sectionLabel = [[[frc sections] objectAtIndex:section]name];
    return [sectionLabel uppercaseString];
}

-(void) refreshData
{
    //This was the turning point for proper MR grouping. The two Properties (activityCategory and activityName) are used as Sort descriptors in the underlying core data methods

    frc = [ListActivity MR_fetchAllSortedBy:@"activityCategory,activityName"
                                  ascending:YES withPredicate:nil
                                    groupBy:@"activityCategory"
                                   delegate:nil];
    [self.myTableView reloadData];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    确保在 Property Inspector 中为 UITableView 选择了“剪辑子视图”,并且表格的 clipsToBounds 未在代码中的某处设置为 NO

    【讨论】:

    • 刚刚检查过。剪辑子视图被选中。我从未听说过 clipsToBounds,在项目中也找不到提及它。
    • 嗯,这是我似乎可以重现的唯一方法。您能否在帖子中添加与表格相关或影响表格的任何代码? (尤其是UITableViewDelegateUITableViewDataSource 我想也是)。
    • Identity Inspector 的“用户定义的运行时属性”有什么不同吗?除此之外,我想知道 ListActivity 是否在 -init: 方法(或其他 init 变体之一)中做任何时髦的事情,但这应该会导致它在两个表中发生......听起来它必须是IB 在某个地方,我只是不是它可能是什么。
    • 我应该更耐心些,但正如您在下面看到的,我删除并替换了有问题的表格视图。但是,我无法想象怎么会有任何用户定义的运行时属性,因为我知道我没有在那里添加任何东西。我同意商店里的任何奇怪现象都应该出现在两张桌子上。无论如何,实体或属性似乎不会对表格视图中的参数产生任何影响。再次感谢!
    【解决方案2】:

    我通过简单地删除 TableView 并拖入一个新的,将其连接起来解决了这个问题。因此问题已解决,但我不知道是什么原因造成的。

    感谢评论的@drhr,以及所有查看的人!

    编辑:

    只是想知道是否有其他人遇到过这个问题。我只是让它在另一个 tableview 上重复,并且必须如上所述解决它。 FWIW,我正在使用 Xcode 5,并正在开发一个 iPhone 应用程序。

    我想修复是好的,但如果能真正知道是什么导致了问题,那就太好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2016-12-18
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多