gpt4 book ai didi

iOS XMPP 如何在表格 View 中的单个部分中显示所有用户

转载 作者:行者123 更新时间:2023-11-29 11:51:06 25 4
gpt4 key购买 nike

我已经使用 NSFetchResultController 获取了 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;

}

最佳答案

如何创建 fetchedResultsController?它负责按部分划分获取的实体。所以你可以简单地通过以下方式创建它:

fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil // pass nil here if you want single section
cacheName:nil];

关于iOS XMPP 如何在表格 View 中的单个部分中显示所有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com