UitableViewCell无法正确显示配件

时间:2014-06-17 23:10:31

标签: ios objective-c uitableview

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

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

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

-(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];
}

1 个答案:

答案 0 :(得分:1)

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

tableview.datasource = [your singleton class instance]

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

希望这有帮助。