简体   繁体   English

带有情节提要的presentViewController显示黑色视图iOS 7.1 xcode 5.1

[英]presentViewController with storyboards shows black view iOS 7.1 xcode 5.1

i did search SO and the web didn't find amy answer . 我确实搜索了SO,但网络上没有找到Amy的答案。
i created in storyboard main UITableViewController called A which have simple button. 我在故事板主UITableViewController中创建了一个名为A的按钮,它具有简单的按钮。 and another ViewController Called B which have webView and close button. 和另一个名为B的ViewController,它们具有webView和关闭按钮。
that is not connected in any form to the main UITableViewController A 没有以任何形式连接到主UITableViewController A
now i like to open the B viewController form A and then close the B ViewController with its own close button . 现在我想打开B viewController窗体A,然后用它自己的关闭按钮关闭B ViewController。
but what ever i try the B view controller is black and blank . 但是我尝试过的B视图控制器都是黑色和空白的。

ViewController B ( the popup view ) ViewController B(弹出视图)

#import "TAFBLoginDialogViewController.h"

@interface TAFBLoginDialogViewController ()

@end

@implementation TAFBLoginDialogViewController

-(id)initWithAppId:(NSString *)apiKey
  requestPremision:(NSString *)requestPremision
          delegate:(id<TAFBLoginDialogViewdelegate>)delegate
          storyBoardName:(NSString*) storyBoardName
{
    //self = [super initWithNibName:@"FBLoginDialog" bundle:nil];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];

    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"FBLoginDialog"];
    if (self) {
        // Custom initialization
        self.apiKey = apiKey;
        self.requestPremision = requestPremision;
        self.delegate = delegate;
    }
    return self;
}



- (IBAction)closeTap:(id)sender
{
    [self.delegate closeTaped];
}


-(void)login
{

}
-(void)logout
{


}
-(void)checkForAccessToken:(NSString*)urlString
{

}
-(void)checkLoginRequired:(NSString*)urlString
{
    [self.delegate displayRequired];
}

- (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.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

UITableViewController A ( the main view controller from which i try to open B) UITableViewController A(我尝试从中打开B的主视图控制器)

#import "TAFMETableViewController.h"


@interface TAFMETableViewController ()
{
}
@end

@implementation TAFMETableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void) awakeFromNib
{


    [super awakeFromNib];
}
- (void)viewDidLoad
{
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return cell;
}


- (IBAction)handleOpenFBDialog:(id)sender {
    UIStoryboard * storyboard = self.storyboard;
    NSString * storyboardName = [storyboard valueForKey:@"name"];

    self.appId = @"11111";
    self.permissions =@"public_stream";

    if(_loginDialogView ==nil)
    {
        self.LoginDialogViewController = [[TAFBLoginDialogViewController alloc] initWithAppId:_appId
                                                               requestPremision:_permissions
                                                                delegate:self storyBoardName:storyboardName];
        self.loginDialogView = _LoginDialogViewController.view;
    }

    [self.LoginDialogViewController checkLoginRequired:@"tst"];

    NSLog(@"Click!");
}


-(void)accessTokenFound:(NSString*)accessToken
{
    NSLog(@"accessTokenFound Click!");
}
-(void)displayRequired
{
    NSLog(@"displayRequired Click!");
    [self presentViewController:_LoginDialogViewController animated:YES completion:nil];
}
-(void)closeTaped
{
    NSLog(@"closeTaped Click!");
    [self dismissViewControllerAnimated:NO completion:nil];
}


@end

header file : 头文件:

@protocol TAFBLoginDialogViewdelegate

-(void)accessTokenFound:(NSString*)accessToken;
-(void)displayRequired;
-(void)closeTaped;

@end


@interface TAFBLoginDialogViewController : UIViewController<UIWebViewDelegate>
{
    //ivars
//    UIWebView *_webview;
//    NSString* _apiKey;
//    NSString* _requestPremision;
//    id <TAFBLoginDialogViewdelegate> _delegate;
}

@property (retain) IBOutlet UIWebView *webView;
@property (copy) NSString *apiKey;
@property (copy) NSString *requestPremision;
@property (assign) id<TAFBLoginDialogViewdelegate> delegate;

-(id)initWithAppId:(NSString*)apiKey
          requestPremision:(NSString*)requestPremision
          delegate:(id<TAFBLoginDialogViewdelegate>)delegate
          storyBoardName:(NSString*) storyBoardName;

- (IBAction)closeTap:(id)sender;
-(void)login;
-(void)logout;
-(void)checkForAccessToken:(NSString*)urlString;
-(void)checkLoginRequired:(NSString*)urlString;


@end

I have button in the TableView A that trigger : 我在触发的TableView A中有一个按钮:

- (IBAction)handleOpenFBDialog:(id)sender  

then this function init the ViewController B and the invoking : 然后此函数初始化ViewController B并调用:

[self.LoginDialogViewController checkLoginRequired:@"tst"];

which supposed to show the ViewController B but all it does shows black screen . 它应该显示ViewController B,但所有显示黑屏。

in your initWithAppID method you instantiate your view controller from the storyboard and then don't do anything with it. 在您的initWithAppID方法中,您从情节提要中实例化视图控制器,然后对其不执行任何操作。 Then you have an if (self) initialization block but you've never initialized self. 然后,您有一个if(self)初始化块,但从未初始化过self。

It looks like what you want to do is set self equal to the view controller that you instantiated from the storyboard and then set the properties on it. 看起来您想要做的是将self设置为与情节提要中实例化的视图控制器相等,然后在其上设置属性。

It might make more sense to make this a class method instead since your allocating a view controller object and inside it's init method your creating another one from the storyboard and ignoring the one you allocated. 相反,将其设置为类方法可能更有意义,因为您分配了一个视图控制器对象,并且在其init方法内部,您从情节提要中创建了另一个,而忽略了您分配的那个。

+(instancetype) TAFBLoginDialogViewControllerWithAppID:(NSString *)apiKey
  requestPremision:(NSString *)requestPremision
          delegate:(id<TAFBLoginDialogViewdelegate>)delegate
          storyBoardName:(NSString*) storyBoardName
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];

    TAFBLoginDialogViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"FBLoginDialog"];

    // Custom initialization
    viewController.apiKey = apiKey;
    viewController.requestPremision = requestPremision;
    viewController.delegate = delegate;

    return viewController; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM