Xcode 应用内购买 TableView 空白
Xcode In-App Purchase TableView Blank
所以我一直在学习创建应用内购买的教程:
http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial
我卡在了您实际在 table 视图中显示应用内购买的部分。我的意思是,首先他忘了包含那个视图控制器的 .h 文件……所以我不知道里面应该有什么。但我的问题是 table 视图加载正常但没有数据出现在其中。
#import "UpgradeViewController.h"
#import "goIAPHelper.h"
#import <StoreKit/StoreKit.h>
@interface UpgradeViewController () {
NSArray *_products;
}
@end
@implementation UpgradeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"In-App Purchases";
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(reload) forControlEvents:UIControlEventValueChanged];
[self reload];
[self.refreshControl beginRefreshing];
}
// 4
- (void)reload {
_products = nil;
[self.tableView reloadData];
[[goIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
NSLog(@"Products: %@", _products);
[self.tableView reloadData];
}
else{
NSLog(@"Not Quite");
}
[self.refreshControl endRefreshing];
}];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// 5
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _products.count;
NSLog(@"products count: %d", _products.count);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
SKProduct * product = (SKProduct *) _products[indexPath.row];
cell.textLabel.text = product.localizedTitle;
NSLog(@"Product Title: %@", product.localizedTitle);
return cell;
}
@end
我从 IAPHelper 得到了响应,但我在代码的 table 部分放置了很多 NSLog,但它似乎从未达到这一点。日志如下所示:
2015-09-10 11:51:37.905 go[1952:1075517] Not purchased: net.hawkinsd.go.noads
2015-09-10 11:51:37.905 go[1952:1075517] Not purchased: net.hawkinsd.go.pebbles
2015-09-10 11:51:39.377 go[1952:1075517] Loaded list of products...
2015-09-10 11:51:39.378 go[1952:1075517] Products: (
)
所以它基本上停在 "Products" NSLog 并且似乎不会再继续了。
这是我的 UpgradeViewController.h 文件:
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface UpgradeViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
@end
好吧...所以任何遵循该指南(或类似指南)的人都可能 运行 遇到同样的空白问题 table。
基本上 table 没有填充,因为 iTunes 没有返回应用内项目...并且 iTunes 没有返回应用内项目,因为您需要拥有银行业务并填写税务信息。
此外,您还需要填写所有这些信息(和 已经提交了您的应用程序),iAds 才能正常运行。所以这些是 table 将填充的条件。
所以我一直在学习创建应用内购买的教程: http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial
我卡在了您实际在 table 视图中显示应用内购买的部分。我的意思是,首先他忘了包含那个视图控制器的 .h 文件……所以我不知道里面应该有什么。但我的问题是 table 视图加载正常但没有数据出现在其中。
#import "UpgradeViewController.h"
#import "goIAPHelper.h"
#import <StoreKit/StoreKit.h>
@interface UpgradeViewController () {
NSArray *_products;
}
@end
@implementation UpgradeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"In-App Purchases";
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(reload) forControlEvents:UIControlEventValueChanged];
[self reload];
[self.refreshControl beginRefreshing];
}
// 4
- (void)reload {
_products = nil;
[self.tableView reloadData];
[[goIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
NSLog(@"Products: %@", _products);
[self.tableView reloadData];
}
else{
NSLog(@"Not Quite");
}
[self.refreshControl endRefreshing];
}];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// 5
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _products.count;
NSLog(@"products count: %d", _products.count);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
SKProduct * product = (SKProduct *) _products[indexPath.row];
cell.textLabel.text = product.localizedTitle;
NSLog(@"Product Title: %@", product.localizedTitle);
return cell;
}
@end
我从 IAPHelper 得到了响应,但我在代码的 table 部分放置了很多 NSLog,但它似乎从未达到这一点。日志如下所示:
2015-09-10 11:51:37.905 go[1952:1075517] Not purchased: net.hawkinsd.go.noads
2015-09-10 11:51:37.905 go[1952:1075517] Not purchased: net.hawkinsd.go.pebbles
2015-09-10 11:51:39.377 go[1952:1075517] Loaded list of products...
2015-09-10 11:51:39.378 go[1952:1075517] Products: (
)
所以它基本上停在 "Products" NSLog 并且似乎不会再继续了。
这是我的 UpgradeViewController.h 文件:
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface UpgradeViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
@end
好吧...所以任何遵循该指南(或类似指南)的人都可能 运行 遇到同样的空白问题 table。
基本上 table 没有填充,因为 iTunes 没有返回应用内项目...并且 iTunes 没有返回应用内项目,因为您需要拥有银行业务并填写税务信息。
此外,您还需要填写所有这些信息(和 已经提交了您的应用程序),iAds 才能正常运行。所以这些是 table 将填充的条件。