- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在运行和测试我的应用程序时遇到问题。
我一直在使用 GeekyLemon 提供的教程。
第 1 部分:http://www.geekylemon.com/xcode-in-app-purchase-part-1
第 2 部分:http://www.geekylemon.com/xcode-in-app-purchase-part-2
第 3 部分:http://www.geekylemon.com/xcode-in-app-purchase-part-3
第 4 部分:http://www.geekylemon.com/xcode-in-app-purchase-part-4
本教程教您如何在您的应用中使用应用内购买,并使用它为您的应用创建“移除广告”功能。
完成本教程的第二部分后,我决定运行我的代码以查看到目前为止我完成了什么。当我运行我的应用程序时,带有“删除广告”按钮的 View Controller 完美显示。但是,当我单击该按钮时,它会将我带到一个漆黑的屏幕,而不是我希望它转到的 View Controller 。
这是 Storyboard文件中我的两个 View Controller 的屏幕截图。左边的 View Controller 有我的“删除广告”按钮。单击它时,我希望它转到右侧的 View Controller 。
以下是我在模拟器中触摸“删除广告”按钮之前和之后的应用程序屏幕截图:
我的 SettingsViewController.h( Storyboard中我的第一个 View Controller 的自定义类):
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <StoreKit/StoreKit.h>
#import "PurchasedViewController.h"
@interface SettingsViewController : UITableViewController < MFMailComposeViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
@property (weak, nonatomic) IBOutlet UILabel *Label;
- (IBAction)PurchaseItem:(id)sender;
@property (strong, nonatomic) PurchasedViewController *purchaseController;
-(void)Purchased;
@end
我的 SettingsViewController.m:
#import "SettingsViewController.h"
#import "SWRevealViewController.h"
#define k_Save @"Saveitem"
@interface SettingsViewController ()
@property (nonatomic, strong) NSArray *menuItems;
@end
@implementation SettingsViewController
@synthesize Label;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = @selector(revealToggle:);
_sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.7f];
NSUserDefaults *saveapp = [NSUserDefaults standardUserDefaults];
bool saved = [saveapp boolForKey:k_Save];
if (!saved) {
/// not save code here
} else {
///saved code here
Label.text = @"Item has been purchased.";
// Add pan gesture to hide the sidebar
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
// Do any additional setup after loading the view.
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0 && indexPath.section == 3){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://howtocrackthedbq.blogspot.com/"]];
} else if(indexPath.row == 1 && indexPath.section == 1){
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"[How to crack the DBQ] Support request"];
[mailViewController setToRecipients:[NSArray arrayWithObject:@"moappsco@gmail.com"]];
[self presentModalViewController:mailViewController animated:YES];
}
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
[self dismissModalViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)Purchased {
Label.text = @"Item has been purchased.";
NSUserDefaults *saveapp = [NSUserDefaults standardUserDefaults];
[saveapp setBool:TRUE forKey:k_Save];
[saveapp synchronize];
}
- (IBAction)PurchaseItem:(id)sender {
_purchaseController = [[PurchasedViewController alloc] initWithNibName:nil bundle:nil];
_purchaseController.productID = @"com.moappsco.crackingthedbq.dbq1";
[[SKPaymentQueue defaultQueue] addTransactionObserver:_purchaseController];
[self presentViewController:_purchaseController animated:YES completion:NULL];
[_purchaseController getProductID:self];
}
@end
我的 PurchasedViewController.h(我 Storyboard右侧显示的其他 View Controller 的自定义类):
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface PurchasedViewController : UIViewController<SKPaymentTransactionObserver,SKProductsRequestDelegate> {
}
@property (strong, nonatomic) SKProduct *product;
@property (strong, nonatomic) NSString *productID;
@property (strong, nonatomic) IBOutlet UILabel *productTitle;
@property (strong, nonatomic) IBOutlet UITextView *productDescription;
@property (strong, nonatomic) IBOutlet UIButton *buyButton;
- (IBAction)Restore:(id)sender;
- (IBAction)BuyProduct:(id)sender;
- (IBAction)GoBack:(id)sender;
-(void)getProductID:(UIViewController *)viewController;
@end
我的 PurchasedViewController.m:
#import "PurchasedViewController.h"
#import "SettingsViewController.h"
@interface PurchasedViewController ()
@property (strong, nonatomic) SettingsViewController *homeViewController;
@end
@implementation PurchasedViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_buyButton.enabled = NO;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)Restore:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (IBAction)BuyProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (IBAction)GoBack:(id)sender {
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
[self UnlockPurchase];
}
-(void)getProductID:(SettingsViewController *)viewController;{
_homeViewController = viewController;
if([SKPaymentQueue canMakePayments]){
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:self.productID]];
request.delegate = self;
[request start];
} else
_productDescription.text = @"Please enable in-app purchases in your settings.";
}
#pragma mark _
#pragma mark SKProductsRequestDelegate
-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSArray *products = response.products;
if (products.count != 0) {
_product = products[0];
_buyButton.enabled = YES;
_productTitle.text = _product.localizedTitle;
_productDescription.text = _product.localizedDescription;
} else {
_productTitle.text = @"Product not found.";
}
products = response.invalidProductIdentifiers;
for(SKProduct *product in products) {
NSLog(@"Product not found: %@", product);
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:[self UnlockPurchase];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:NSLog(@"Transaction Failed");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
default:
break;
}
}
}
-(void)UnlockPurchase {
_buyButton.enabled = NO;
[_buyButton setTitle:@"Purchased" forState:UIControlStateDisabled];
[_homeViewController Purchased];
}
@end
如果需要,你可以在Github上下载我的xcode项目:https://github.com/MoAppsCo/iOS-Apps/tree/master/How%20to%20crack%20the%20DBQ
最佳答案
您没有正确实例化您的 Controller 。当 Controller 在 Storyboard中时,您不应该使用 initWithNibName:bundle:(用于基于 xib 的 Controller ),您应该在 Storyboard中为您的 Controller 提供一个标识符,并使用:
_purchaseController = [self.storyboard instantiateViewControllerWithIdentifier:@"YourNameHere"];
当然,您也可以通过将一个 segue 从设置 Controller 连接到该 Controller ,然后使用 performSegueWithIdentifier:sender: 来实现。
关于ios - 按下按钮时 UIViewcontroller 不打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21011153/
我希望能够在代码中布局我的 View Controller ,但可以看到界面构建器中显示的布局。 我知道我可以创建一个 UIView 子类,使其 IBDesignable,并将其分配给 View Co
我有一个父 UIViewController(MainVC)。从那里我有 2 个 segue 到 2 个 UIViewControllers:FirstVC(标识符:goFirstVC)和 Secon
我有一个导航 Controller 。第一个viewcontroller 是FirstViewController 的一种。当我在 FirstViewController 中点击一个按钮时,它会将第二
我有一个自定义的动画 UIViewController 过渡,似乎 iOS 中有一个错误会破坏横向布局。在主要动画方法中,我得到了横向和纵向 View 的混合。 (纵向 View 都是纵向的,所以没问
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我有一个 UIViewController,里面有 UITabBar。我正在尝试模仿 UITabBarController。 My question is how do I set or a UIVi
是否有任何方便的方法来确定是否正在从处于后台模式的应用加载 View ? 在 3.X 中,我将依赖 viewDidLoad 进行一些初始化等操作,但是对于 4.X 而言情况并非如此,因为您不能依赖调用
我将主视图 Controller 作为带有 UICollectionView 的 View Controller ,并且填充了照片。 一旦一个单元格被点击,一个新的 View Controller 被
我有一个简单的 UIViewController(单点触控),在 UI 上有一个按钮。现在,我的用例很简单 - 我想在单击按钮时重新加载 UIViewController。在某些线程上,我读到我只需要
我在它上面有一个 UIViewController 1 UIButton(添加为 subview ),在我按下 Button(见下面的图 1)之后,在它上面添加了另一个 UIViewControlle
尝试为 iPad 制作基于 Storyboard的应用程序。在其中,我需要从开始屏幕 (UIViewController) 过渡到主屏幕 (UISplitViewController),然后再到全屏
我想调整 UIViewController 的大小在 Storyboard中,所以我可以使用它的 UIViewController作为弹出 View 。 在大多数网站上,我可以读到这些操作是: 拖一个
我正在尝试从 XIB 或 Storyboard加载 ViewModel 绑定(bind)的 ViewController(使用 MvvmCross 5.0.6)。我的应用程序的逻辑是,该 View C
我正在构建一个锻炼应用程序。我的 TableViewController 中有一系列练习,每个单元格显示不同的练习。单元格转到 UIViewController。在 UIViewController
我正在尝试从 XIB 或 Storyboard加载 ViewModel 绑定(bind)的 ViewController(使用 MvvmCross 5.0.6)。我的应用程序的逻辑是,该 View C
我有一个 UIViewController,它有一个模式窗口,我想在整个界面上展示它,包括 UITabBar。 我的应用程序层次结构是这样的: UITabBarController (A) ->
我想显示另一个 ViewController 的缩小“预览”在另一个 ViewController .这可能吗?不需要交互,因此它基本上可以是屏幕截图,但按比例缩小。我可以通过手动截屏并将其保存为图像
我正在开发一个应用程序,其中 UIViewController ( firstViewController ) 包含一些 UILabels , 一个 UIButton , 和 UIView ( sub
我的标签栏中有五个标签栏项目。第五项是弹出ViewController。因此,当我单击该按钮时,当前 Controller 中将显示一个弹出窗口。我使用 UIViewController 作为子类来实
我正在开发 iOS 应用程序。 我的应用程序有 6 个按钮,每个按钮都有每个标签栏控件。 so Main screen is [btn1] [btn2] [btn3] [btn4] [btn5] [b
我是一名优秀的程序员,十分优秀!