【发布时间】:2014-01-10 16:01:39
【问题描述】:
我有一个带有可展开/可折叠部分和固定部分标题的 tableView,我想对其进行维护。 这是执行此操作的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 6;
}
+ (NSString*) titleForHeaderForSection:(int) section
{
switch (section)
{
case 0 : return @"Overdue";
case 1 : return @"Today";
case 2 : return @"Tomorrow";
case 3 : return @"Upcoming";
case 4 : return @"Someday";
case 5 : return @"Completed";
// default : return [NSString stringWithFormat:@"Section no. %i",section + 1];
}
}
目前,我正在使用以下代码填充行:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section)
{
case 2 : return 1;
case 3 : return 30;
default : return 8;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
switch (indexPath.row)
{
case 0 : cell.textLabel.text = @"First Cell"; break;
case 1 : cell.textLabel.text = @"Second Cell"; break;
case 2 : cell.textLabel.text = @"Third Cell"; break;
case 3 : cell.textLabel.text = @"Fourth Cell"; break;
case 4 : cell.textLabel.text = @"Fifth Cell"; break;
case 5 : cell.textLabel.text = @"Sixth Cell"; break;
case 6 : cell.textLabel.text = @"Seventh Cell"; break;
case 7 : cell.textLabel.text = @"Eighth Cell"; break;
default : cell.textLabel.text = [NSString stringWithFormat:@"Cell %i",indexPath.row + 1];
}
//cell.detailTextLabel.text = ...;
return cell;
}
但我想从核心数据实体填充行,这是我的 NSFetchedResultsController:
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"ToDoItem" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"tdText" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil
cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
核心数据实体是'ToDoItem',我最终想要的是每个对象都出现在tableView的右侧部分中。我需要你的帮助和建议。
为了让我的问题更清楚一点,我将创建一个名为 tdDate 的属性,该属性应该是过滤键,以决定在哪个部分显示对象。考虑到具有当前日期的对象今天将出现在 TODAY 部分下,明天它应该出现在 OVERDUE 部分下......
【问题讨论】:
标签: ios uitableview core-data