Я выбрал пользователей XMPP, используя NSFetchResultController, но он отображает онлайн-пользователей в одном разделе и пользователей в автономном режиме в другом разделе, я хочу отображать всех пользователей в одном разделе, i Невозможно объединить всех пользователей. Как отображать в отдельном разделе таблицы.iOS XMPP Как отобразить всех пользователей в одном разделе в таблице view
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[[self fetchedResultsController] sections] count];
}
- (NSString *)tableView:(UITableView *)sender titleForHeaderInSection:(NSInteger)sectionIndex
{
NSArray *sections = [[self fetchedResultsController] sections];
if (sectionIndex < [sections count])
{
id <NSFetchedResultsSectionInfo> sectionInfo = sections[sectionIndex];
int section = [sectionInfo.name intValue];
switch (section)
{
case 0 : return @"Available";
case 1 : return @"Away";
default : return @"Offline";
}
}
return @"";
}
- (void)configurePhotoForCell:(UITableViewCell *)cell user:(XMPPUserCoreDataStorageObject *)user
{
if (user.photo != nil)
{
cell.imageView.image = user.photo;
}
else
{
NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule] photoDataForJID:user.jid];
if (photoData != nil)
cell.imageView.image = [UIImage imageWithData:photoData];
else
cell.imageView.image = [UIImage imageNamed:@"defaultPerson"];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
NSArray *sections = [[self fetchedResultsController] sections];
if (sectionIndex < [sections count])
{
id <NSFetchedResultsSectionInfo> sectionInfo = sections[sectionIndex];
return sectionInfo.numberOfObjects;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell =(UITableViewCell *)[self.usersTable dequeueReusableCellWithIdentifier:@"users"];
UILabel *nameLabel =(UILabel *)[cell viewWithTag:10];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
XMPPUserCoreDataStorageObject *user = [[self fetchedResultsController] objectAtIndexPath:indexPath];
nameLabel.text = user.displayName;
return cell;
}
Спасибо за вашу помощь, вы, пожалуйста, помогите мне, что я должен вернуться к numberOfRowsInSection и numberOfSectionsInTable. , –
Я немного смутился, но это сработало, как шарм, который вы спасли в день. Спасибо. , , –
В вашем коде он возвращает количество разделов 'fetchedResultsController'. Но поскольку теперь раздел только один из-за изменения инициализации 'fetchedResultsController', он возвращает 1 раздел. Поэтому никаких изменений в 'fetchedResultsController' не требуется. – dosi