Je n'arrive pas à transférer des données de mon NSArray pour remplir ma vue Table. J'ai regardé autour et essayé quelques choses différentes, mais pas de chance jusqu'à présent.Mise en place de NSArray dans TableView
Voici mon code:
#import "ListFilmController.h"
#import <WindowsAzureMobileServices/WindowsAzureMobileServices.h>
#import <QuartzCore/QuartzCore.h>
#import "AppDelegate.h"
@interface ListFilmController()
@end
@implementation ListFilmController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
MSClient *client = [(AppDelegate *) [[UIApplication sharedApplication] delegate] client];
MSTable *itemTable = [client tableWithName:@"filmbuff"];
[itemTable readWithCompletion:^(NSArray *items, NSInteger totalCount, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
}
else {
_allFilms = items;
NSLog(@"Item inserted, array: %@", items);
}
}];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_allFilms count];;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier [email protected]"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[_allFilms objectAtIndex:indexPath.row];
return cell;
}
Je tire les données du tableau d'Azure et de le transférer à un tableau. Maintenant je le veux pour que chaque cellule soit une rangée différente de ce tableau. auriez vous des idées pour faire ça?
Etes-vous sûr que le tableau '_allFilms' est rempli avec des données? – Stonz2
'readWithCompletion' est une tâche asynchrone, votre tableview pourrait être en cours de chargement avant d'avoir des données –
Vous pouvez essayer d'initialiser votre tableau _allFilms avant la ligne" readWithCompletion ". Après cela, dans le bloc d'achèvement où vous assignez des "items" à "_allFilms" vous devriez ajouter quelque chose comme "[_myTable reloadData];". À ce stade, votre tableau _allFils est déjà rempli. – Alex