Ios 在从Parse.com上PFUser的列类型数组获得的UITableView上显示用户数据

Ios 在从Parse.com上PFUser的列类型数组获得的UITableView上显示用户数据,ios,objective-c,uitableview,parse-platform,nsmutablearray,Ios,Objective C,Uitableview,Parse Platform,Nsmutablearray,我在UIView(UserListVC)中创建了UITableView,以显示Parse.com上存储在列类型数组中的用户数据。名为“followers”的列包含一行中确实喜欢该用户的PFUser objectId的数组(在本例中为当前用户) 在userListVC.m中: @implementation UserListViewController { NSMutableArray *tableData; } - (void)viewDidLoad { [super view

我在UIView(UserListVC)中创建了UITableView,以显示Parse.com上存储在列类型数组中的用户数据。名为“followers”的列包含一行中确实喜欢该用户的PFUser objectId的数组(在本例中为当前用户)

在userListVC.m中:

@implementation UserListViewController
{
    NSMutableArray *tableData;
}    

- (void)viewDidLoad {
[super viewDidLoad];

/*
tableData = [NSMutableArray arrayWithObjects:@"user1", @"user2", nil];
NSLog(@"tableData --> %@", tableData);
*/
tableData = [[NSMutableArray alloc] init];  

PFQuery *userQuery = [PFQuery queryWithClassName:kPAWParseUserClassKey];
[userQuery whereKey:kPAWParseUsernameKey equalTo:[PFUser currentUser].username];
userQuery.cachePolicy = kPFCachePolicyNetworkElseCache;
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *users, NSError *error)
 {
     if( !error )
     {
         NSArray *array = [users valueForKey:@"followings"];
         for (int i = 0; i <= array.count; i++)

             PFQuery *followingsQuery = [PFUser query];
             [followingsQuery whereKey:@"objectId" equalTo:[[[users valueForKey:@"followings"] objectAtIndex:0] objectAtIndex:i]];
             followingsQuery.cachePolicy = kPFCachePolicyNetworkElseCache;

             [followingsQuery findObjectsInBackgroundWithBlock:^(NSArray *followings, NSError *error) {
                 if (!error) {
                     NSLog(@"following names --> %@", [followings valueForKey:kPAWParseUsernameKey]);

                     [tableData addObject:[followings valueForKey:kPAWParseUsernameKey]]; //??
                     [self.tableView reloadData];
                     NSLog(@"table data --> %@", tableData);
                 }
             }];
     }
 }];
}
我认为最好还为方法(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath提供代码,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *tableIdentifier = @"TableItem";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
}
NSLog(@"table data xxxxx --> %@", tableData);
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];

return cell;
}
上述方法从未运行过,但如果我使用样本数据进行测试,它确实会运行。更具体地说,我的问题是:

  • 这是UIView,其中包含UITableView。我不知道如何[self.tableView reloadData]正确。我的意思是如何声明tableView。在这种情况下,我会这样做:

    @interface UserListViewController ()
    @property (weak, nonatomic) UITableView *tableView;//????
    @end
    
  • 为什么方法(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath从未运行


仅回答以下两个具体问题:

  • 将tableView连接到.h文件中的IBOutlet,并在.m文件中进行合成,然后:

    [self.tableView reloadData];
    
在异步块内执行上述操作

  • 如果按照上述建议执行,将运行方法(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

然而,还有其他问题,但我认为它们超出了这个问题的范围。

您使用什么代码“通过使用从“追随者”列中获取的数据数组从用户类中获取用户名”?我还不知道如何做到这一点。我已经搜索了很多次了,但还没有找到。@lee是的,你说得100%对!您可以使用
[self.tableView reloadData]在异步块内更新tableView在您的
[tableData addObject:[以下值forkey:kPAWParseUsernameKey]];/行。很好的工作,大部分事情都是你自己想出来的@是的,tableData日志仍然是空的,因为在调用该行时tableData尚未就绪,因为tableData在异步块期间在后台填充。但是,如果只需要重新加载tableview,请在async块中这样做。如果要打印出表数据,还必须在我在异步块中提到的行之后进行打印。@不,您可以像我说的那样在异步块中重新加载表。
[self.tableView reloadData];