Objective c UITableView不是';行不通

Objective c UITableView不是';行不通,objective-c,uitableview,parse-platform,Objective C,Uitableview,Parse Platform,我试图在UIViewController中创建一个UITableView,但我遇到了问题。如果我直接设置文本,它会显示(cell.username.text),但如果我尝试用PFQuery(parse.com)填充它,则不会显示任何内容 //DetailViewController.h #import <UIKit/UIKit.h> #import <Parse/Parse.h> @interface DetailViewCont

我试图在UIViewController中创建一个UITableView,但我遇到了问题。如果我直接设置文本,它会显示(cell.username.text),但如果我尝试用PFQuery(parse.com)填充它,则不会显示任何内容

    //DetailViewController.h    
    #import <UIKit/UIKit.h>
    #import <Parse/Parse.h>

    @interface DetailViewController : UIViewController{

    }

    @property (strong, nonatomic) PFObject *place;
    @property (strong, nonatomic) IBOutlet PFImageView *userPhoto;
    @property (strong, nonatomic) IBOutlet UILabel *username;
    @property (strong, nonatomic) IBOutlet UILabel *message;
    @property (strong, nonatomic) IBOutlet UILabel *distance;
    @property (strong, nonatomic) IBOutlet UILabel *checkCount;
    @property (strong, nonatomic) IBOutlet PFImageView *photo;
    @property (strong, nonatomic) IBOutlet UIScrollView *scroller;
    @property (strong, nonatomic) IBOutlet UITableView *commentsTableView;

    - (IBAction)checkMarkButton:(UIButton *)sender;


    @end

//DetailViewController.m
#import "DetailViewController.h"
#import "CommentsViewController.h"

@interface DetailViewController (){

    CommentsViewController *test;
}

@end

@implementation DetailViewController

@synthesize place;
@synthesize userPhoto, message, username, checkCount, photo, scroller, commentsTableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    test = [[CommentsViewController alloc] init];
    self.commentsTableView.delegate = test;
    self.commentsTableView.dataSource = test;

    [test commentsQuery:place];
}

//CommentsViewController.h
#import <Parse/Parse.h>

@interface CommentsViewController : UITableViewController{

}

@property (strong, nonatomic) PFObject *place;

- (void)commentsQuery:(PFObject *)object;

@end

//CommentsViewController.m
#import "CommentsViewController.h"
#import "DetailViewController.h"
#import "CommentsCell.h"

@interface CommentsViewController (){
    NSArray *commentsArray;
}



@end

@implementation CommentsViewController

@synthesize place;



- (void)commentsQuery:(PFObject *)object {

    place = object;

    PFQuery *query1 = [PFQuery queryWithClassName:@"activity"];
    [query1 whereKey:@"type" equalTo:@"comment"];
    [query1 whereKey:@"place" equalTo:place];
    [query1 orderByDescending:@"createdAt"];
    [query1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error){
            commentsArray = [[NSArray alloc]initWithArray:objects];
            NSLog(@"%lu", (unsigned long)[commentsArray count]);
        }
    }];

}






-  (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [commentsArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *CellIdentifier = @"Cell";
    CommentsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[CommentsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    PFObject *tempObj = [commentsArray objectAtIndex:indexPath.row];

    cell.username.text = @"username";
    cell.comment.text = [tempObj objectForKey:@"content"];
    cell.userThumbnail.file = [tempObj objectForKey:@"userThumbnail"];
    [cell.userThumbnail loadInBackground];



    return cell;
}
@end
//DetailViewController.h
#进口
#进口
@界面详细信息ViewController:UIViewController{
}
@属性(强,非原子)PFObject*place;
@属性(强,非原子)IBMImageView*userPhoto;
@属性(强,非原子)IBUILabel*用户名;
@属性(强,非原子)IBUILabel*消息;
@性质(强,非原子)IBUILabel*距离;
@属性(强,非原子)IBUILabel*检查计数;
@属性(强,非原子)IBMImageView*照片;
@属性(强,非原子)IBUIScrollView*滚动条;
@属性(强,非原子)IBUITableView*commentsTableView;
-(iAction)选中标记按钮:(UIButton*)发送器;
@结束
//DetailViewController.m
#导入“DetailViewController.h”
#导入“CommentsViewController.h”
@接口详细信息ViewController(){
评论视频控制器*测试;
}
@结束
@实现细节视图控制器
@综合场所;
@合成用户照片、消息、用户名、支票计数、照片、滚动条、评论视图;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
测试=[[CommentsViewController alloc]init];
self.commentsTableView.delegate=测试;
self.commentsTableView.dataSource=测试;
[测试注释:地点];
}
//CommentsViewController.h
#进口
@界面注释ViewController:UITableViewController{
}
@属性(强,非原子)PFObject*place;
-(void)commentsQuery:(PFObject*)对象;
@结束
//CommentsViewController.m
#导入“CommentsViewController.h”
#导入“DetailViewController.h”
#导入“CommentsCell.h”
@接口注释viewcontroller(){
NSArray*评论Sarray;
}
@结束
@实现注释viewcontroller
@综合场所;
-(void)commentsQuery:(PFObject*)对象{
地点=对象;
PFQuery*query1=[PFQuery queryWithClassName:@“活动”];
[query1 whereKey:@“type”equalTo:@“comment”];
[查询1 whereKey:@“地点”等于:地点];
[query1 orderByDescending:@“createdAt”];
[query1 findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(!错误){
commentsArray=[[NSArray alloc]initWithArray:objects];
NSLog(@“%lu”,无符号长)[commentsArray计数];
}
}];
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[commentsArray计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;
{
静态NSString*CellIdentifier=@“Cell”;
CommentsCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
如果(单元格==nil){
cell=[[CommentsCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
PFObject*tempObj=[commentsArray objectAtIndex:indexath.row];
cell.username.text=@“username”;
cell.comment.text=[tempObj objectForKey:@“content”];
cell.userThumbnail.file=[tempObj objectForKey:@“userThumbnail”];
[cell.user缩略图加载背景];
返回单元;
}
@结束

我的问题是调用重载数据。我在这里找到了答案,答案是有效的

你确定你从字典中得到的不是空的吗?也许你可以记录它并用结果更新你的帖子?我认为你混合了UITableView IBOutlet(事实上是显示的),然后是你的自定义子类UITableViewController@Mr_bem是的,commentsQuery在表中显示为null,但是如果我将nslog放在实际查询中,它可以正常工作。我唯一的猜测是,我必须刷新表,因为它是在查询完成之前调用的,但由于IBMOutlet UITableView*commentsTableView位于DetailViewController中,我无法访问[reloadData],因此如何刷新表?