2015-07-11 4 views
0

Я новичок в программировании iOS, и я пытаюсь отобразить данные анализа в виде коллекции. Я пытаюсь отобразить строку в ключе на ярлыке ячейки коллекции. Я хватаю «Папки» в viewWillAppear:, но, похоже, они не отображаются на ярлыке. Мой код ниже.Невозможно отобразить данные анализа в UICollectionView

@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; 
} 
+0

возможно дубликат [Установка PFObject и UILabel] (http://stackoverflow.com/questions/25142060/setting-pfobject-in-to-uilabel) –

ответ

0

Вы должны установить текст лейбла в папку (и независимо от свойств папки, которую вы хотите, чтобы показать), а не массив:

titleLabel.text = folder 

Кроме того, это не нужно вызывать reloadData в cellForItemAtIndexPath ,

0

Я выяснил, как отображать ячейки, соединяя ярлык моей ячейки с IBAction Collection вместо обычного IBAction. Я пытаюсь создать приложение для заметок, и единственная проблема заключается в том, что каждая ячейка просто говорит «Ярлык» вместо имени папки, которое сохраняется в Parse. Не уверен, что я делаю неправильно здесь:

@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; 

} 
Смежные вопросы