我無法從我的NSArray傳輸數據來填充我的表格視圖。我環顧四周,嘗試了一些不同的東西,但目前還沒有運氣。把NSArray放入TableView
這裏是我的代碼:
#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;
}
我從Azure中拉陣列中的數據並將其傳送到一個數組。現在我需要它,以便每個單元格與該陣列不同。任何想法如何做到這一點?
您確定'_allFilms'數組正在填充數據嗎? – Stonz2
'readWithCompletion'是一個異步任務,你的tableview可能在你有數據之前加載 –
你可以嘗試在「readWithCompletion」行之前初始化你的_allFilms數組。之後,在您將「items」分配給「_allFilms」的完成塊中,您應該添加諸如「[_myTable reloadData];」之類的內容。在這一點上,你的_allFils數組已經被填充。 – Alex