我正在开发一个应用内购买应用程序,在获得产品专业应用商店后,我试图将这些产品加载到 uitableview 中。问题是:当我获得产品列表时,我无法在表格中加载数据。当我使用静态值而不使用 reloadData 创建表时,一切正常。
除了加载桌子外,一切都运行良好
我的代码在哪里:
@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