Ios 无法在UICollectionView中显示分析数据

Ios 无法在UICollectionView中显示分析数据,ios,parse-platform,Ios,Parse Platform,我不熟悉iOS编程,我正在尝试在集合视图中显示解析数据。我试图在集合视图单元格标签的键中显示字符串。我正在抓取视图中将显示的文件夹:但似乎无法将它们显示在标签中。我的代码如下 @interface FoldersViewController () @end @implementation FoldersViewController - (void)viewDidLoad { [super viewDidLoad]; PFUser *currentUser = [PFUse

我不熟悉iOS编程,我正在尝试在集合视图中显示解析数据。我试图在集合视图单元格标签的键中显示字符串。我正在抓取视图中将显示的文件夹:但似乎无法将它们显示在标签中。我的代码如下

@interface FoldersViewController ()

@end

@implementation FoldersViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"current user %@", currentUser.username);
    } else {
        [self performSegueWithIdentifier:@"showLogin" sender:self];
    }
}


- (void)viewWillAppear:(BOOL)animated {
    PFQuery *query = [PFQuery queryWithClassName:@"Folders"];
    [query whereKeyExists:@"folderName"];
    [query orderByAscending:@"folderName"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        } else {
            // We found folders
            self.folders = objects;
            [self.collectionView reloadData];
            NSLog(@"Retrieved %d folders", (int)[self.folders count]);
        }
    }];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [self.folders count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"Cell";

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    PFObject *folder = [self.folders objectAtIndex:indexPath.row];

    UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
    titleLabel.text = (NSString*)self.folders;

    [collectionView reloadData];
    return cell;
}

您应该将标签的文本设置为文件夹以及要显示的文件夹的任何属性,而不是数组:

titleLabel.text = folder

另外,无需在cellForItemAtIndexPath中调用reloadData。

我通过将单元格标签与iAction集合(而不是常规iAction)连接,找到了显示单元格的方法。我正在尝试构建一个笔记应用程序,唯一的问题是每个单元格只显示标签,而不是解析时保存的文件夹名称。不确定我做错了什么:

@interface FoldersViewController ()

@end

@implementation FoldersViewController

- (void)viewDidLoad {
[super viewDidLoad];

PFUser *currentUser = [PFUser currentUser];
if (currentUser) {
    NSLog(@"current user %@", currentUser.username);
} else {
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}
}


-(void)viewWillAppear:(BOOL)animated {
PFQuery *query = [PFQuery queryWithClassName:@"Folders"];
[query whereKeyExists:@"folderName"];
[query orderByAscending:@"folderName"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    } else {
        //We found folders
        self.folders = objects;
        [self.collectionView reloadData];
        NSLog(@"Retrieved %d folders", (int)[self.folders count]);
    }
}];
}



- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.folders count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

FolderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

UILabel *folder = (UILabel *)self.folders;

cell.folderTitle = (NSArray *)folder;


return cell;

}
可能重复的