【问题标题】:ios pushing to navigationController ends in black screenios推送到navigationController以黑屏结束
【发布时间】:2025-11-20 16:35:01
【问题描述】:

我尝试通过其在线文档在 iOS 应用中实现条带化。到目前为止一切都很好,现在将 paymentView 推送到我的导航控制器堆栈上,我得到了一个完全破碎的屏幕。以为条纹视图有问题,但是当我没有登录时(请参见下面的代码 - 没有给出标识令牌)并且正在推送登录屏幕,它也完全是黑色的。该视图不会有问题,因为如果我在此视图之前从另一个视图推送登录视图,它会加载得很好。

那么为什么通过下面的 buyButtonAction 推送视图给我黑屏/搞砸了屏幕?! 我已经做了几个小时了.. 似乎没有任何效果。

一张照片:

the important code part:

@interface PaymentViewController ()

@end

@implementation PaymentViewController

@synthesize stripeCard = _stripeCard;
@synthesize stripeView;
@synthesize passedProductId;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{


    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.stripeView = [[STPView alloc] initWithFrame:CGRectMake(15,20,290,55)
                                              andKey:@"pk_test_45mqixOu8N9S4lQ6cdn1OXBD"];
    self.stripeView.delegate = self;
    [self.view addSubview:self.stripeView];

}

还有电话:

-(void)buyButtonAction:(id)sender
{
    tokenClass *tokenObject = [tokenClass getInstance];
    NSLog(@"%@", tokenObject.token);
    if (tokenObject.token == nil) {
        LoginController *loginController = [[LoginController alloc] init];
        [self.navigationController pushViewController:loginController animated:YES];
    } else {
        NSLog(@"%@", tokenObject.token);
        CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView];
        NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];
        PaymentViewController *payView = [[PaymentViewController alloc] init];
        payView.passedProductId = [[self.productData valueForKey:@"id"] objectAtIndex:hitIndex.row];
        NSLog(@"passing %@", payView.passedProductId);
        // push payment view
        payView.navigationItem.title = @"One-Click-Payment";
        [self.navigationController pushViewController:payView animated:YES];
    }
}

【问题讨论】:

    标签: ios iphone objective-c


    【解决方案1】:

    我们可以看到导航栏后面有一个视图。这是一个与 iOS 7 相关的问题。将此行添加到您的 viewDidLoad:

     if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;
    

    或者通过将64 添加到y 来更改您的self.stripeView 框架:

    CGRectMake(15,84,290,55)
    



    有用的链接:https://*.com/a/18103727/1835155

    【讨论】:

    • 感谢您关闭了编辑字段,但设计仍然从根本上被破坏(黑色背景 - 似乎没有加载视图,然后编辑字段都写在彼此之上..)
    • 您是否在您的PaymentViewController 中尝试过self.view.backgroundColor = [UIColor whiteColor]
    • 好吧对不起,我意识到这确实是一个空白视图。因此调整背景颜色有效,谢谢!阅读条带文档后,我的理解是,它是最终用户的完整视图,因此对质量不佳感到疑惑。谢谢!