我正在開發一個應用內購買應用程序,並獲得產品親應用程序商店後,我試圖加載這些產品在一個可用視圖。問題是:當我得到產品列表時,我無法在表格中加載數據。當我使用靜態值創建表而不使用reloadData時,一切正常。從UITableViw reloadData不起作用
Eeverything工作正常旁裝載表
這裏是我的代碼:
@synthesize products;
@synthesize productsTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSSet *productIndentifiers = [NSSet setWithObjects:@"Prod01",@"Prod02",@"Prod03",nil];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIndentifiers];
[productsRequest start];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:TRUE];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setProductsTableView:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.products.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
[self.productsTableView dequeueReusableCellWithIdentifier:@"Cell"];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
SKProduct *product = [self.products objectAtIndex:indexPath.row];
cell.textLabel.text = product.localizedTitle;
}
return cell;
}
#pragma mark - SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSLog(@"%@", response.products);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:FALSE];
[self.productsTableView reloadData];
}
- (void)dealloc {
[productsTableView release];
[super dealloc];
}
@end
謝謝,可能是有另一個問題,當我修復它,我刪除了產品數組歸屬。 – Rafael