У меня есть tableView с расширяемыми/сжимаемыми разделами и заголовками фиксированного раздела, которые я хочу поддерживать. Это код, чтобы сделать это:Основные объекты данных в разных разделах таблицыView
- (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, и этот атрибут должен быть ключом фильтрации, чтобы решить, в соответствии с которым раздел должен быть объект показан. Принимая во внимание, что сегодня в разделе СЕГОДНЯ будет отображаться объект с текущей датой, завтра он должен появиться в разделе OVERDUE ...
Спасибо, но в моем случае ключ для распределения объектов по разделам может меняться каждый день. – mvasco
@mvasco Что значит? –
Я имею в виду, что разделы должны включать ToDoItems, которые имеют дату (может быть атрибутом, называемым tdDate), этот атрибут можно использовать в качестве фильтра, чтобы сделать распределение по разделам, но затем я должен найти способ обновить ключ в зависимости от текущую дату. – mvasco