【发布时间】: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