gpt4 book ai didi

ios - UitableViewCell 无法正确显示配件

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

我有一个好友 ListView Controller ,允许用户查看待处理的好友请求。 isPending 方法首先用于查看特定用户是否与当前用户有待处理的好友请求。

-(BOOL)isPending:(PFUser *)user
{
for (PFUser *pending in self.Pending){
if ([pending.objectId isEqualToString:user.objectId]){
return YES;
}
}
return NO;
}

此方法在 TableViewController 的 cellForRowAtIndexPath 方法中调用。我遇到的问题是,如果我在 tableViewController 中运行查询,则会正确显示待处理的用户。当我将查询移动到单例数据源类时,我设置了一个委托(delegate)方法,当从查询返回数据时调用该方法。

-(void)pendingFriendsQuarryDidFinishWithData{
self.Pending = [NSMutableArray arrayWithArray:dataHolder.getPendingFriendsList];
[self.tableView reloadData];
}

调用 reloadData 不会导致复选标记出现在用户名旁边。

编辑:这里是 cellForRowAtIndexPath 的代码。它不会随着单例而改变。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

// Configure the cell...
PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
cell.textLabel.text = user.username;
cell.detailTextLabel.text = user.email;
cell.imageView.image = [UIImage imageNamed:@"Treehouse.png"];

if([self isPending:user]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}


return cell;
}

改变的是数据的获取方式。这里没有单例是代码

-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
/*
self.currentUser = [PFUser currentUser];
if (self.currentUser != nil){
PFQuery *userQuery = [PFUser query];
PFQuery *pendingUser = [PFUser query];
PFRelation *friendRelation = [self.currentUser relationForKey:@"friendRelation"];
PFQuery *existingFriends = [friendRelation query];
PFQuery *pendingFriends = [PFQuery queryWithClassName:@"FriendRequest"];
userQuery.cachePolicy = kPFCachePolicyCacheThenNetwork;
pendingFriends.cachePolicy = kPFCachePolicyCacheThenNetwork;
[pendingFriends whereKey:@"fromUser" equalTo:self.currentUser.objectId];
[pendingFriends whereKey:@"status" equalTo:@"Pending"];
[userQuery whereKey:@"objectId"doesNotMatchKey:@"toUser" inQuery:pendingFriends];
[userQuery whereKey:@"objectId" doesNotMatchKey:@"objectId" inQuery:existingFriends];
[userQuery orderByAscending:@"username"];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error){
NSLog(@" Error %@ %@", error, [error userInfo] );
}else{
NSLog(@"All Users Array Starts Here: %@", objects);
self.allUsers = objects;
[self.tableView reloadData];
}
}];
[pendingUser whereKey:@"objectId" matchesKey:@"toUser" inQuery:pendingFriends];
[pendingUser orderByAscending:@"username"];
[pendingUser findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error){
NSLog(@"%@ %@", error, [error userInfo]);
}else{
[self.Pending addObjectsFromArray:objects];
NSLog(@"Pending Friends Array Stars here: %@", self.Pending);
}
}];
}
*/
}

单例

- (void)viewDidLoad
{

dataHolder = [DataHolder sharedInstance];
dataHolder.delegate = self;

self.friends = [NSMutableArray new];
self.allUsers = [NSMutableArray new];
self.allUsers = [NSMutableArray arrayWithArray:dataHolder.getAllUsersWithQuarry];
self.Pending = [NSMutableArray new];
self.Pending = [NSMutableArray arrayWithArray:dataHolder.getPendingFriendsListWithQuarry];
[super viewDidLoad];
NSLog(@"Now in Connection Editor");

}

-(void)allUsersQuarryDidFinishWithData{
self.allUsers = [NSMutableArray arrayWithArray:dataHolder.getAllUsers];
[self.tableView reloadData];
}

-(void)pendingFriendsQuarryDidFinishWithData{
self.Pending = [NSMutableArray arrayWithArray:dataHolder.getPendingFriendsList];
[self.tableView reloadData];
}

最佳答案

愚蠢的问题,你是否将你的 tableviewcontroller 的数据源设置为指向你的单例数据源?

tableview.datasource = [your singleton class instance]

并确保您在调试器中步入它。

希望这对您有所帮助。

关于ios - UitableViewCell 无法正确显示配件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24274759/

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