2014-07-26 84 views
0

我做了搜索,並且網絡沒有找到答案。
我在storyboard主要的UITableViewController中創建了一個名爲A的按鈕。 和另一個ViewController叫做B,它有webView和關閉按鈕。
沒有以任何形式連接到主UITableViewController A
現在我想打開B viewController窗體A,然後用它自己的關閉按鈕關閉B ViewController。
但我曾嘗試B視圖控制器是黑色和空白。presentViewController與故事板顯示黑色視圖iOS 7.1 xcode 5.1

的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(主視圖控制器從我嘗試打開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 [email protected]"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 

頭文件:

@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 

我在TableView A中有一個觸發按鈕:

- (IBAction)handleOpenFBDialog:(id)sender 

那麼這個函數初始化的ViewController中乙 和調用:

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

這應該顯示的ViewController乙 但它所做的一切顯示黑屏。

回答

1

在你的initWithAppID方法中,你從故事板實例化你的視圖控制器,然後不要對它做任何事情。然後你有一個if(self)初始化塊,但你從來沒有初始化自己。

它看起來像你想要做的是設置自我等於從故事板實例化的視圖控制器,然後設置它的屬性。

將它作爲一個類方法可能更有意義,因爲您將分配一個視圖控制器對象並在其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; 
} 
+0

感謝您的回答即時得到那些我想我沒有設置正確的apiKey和所有其他屬性的錯誤: 屬性「apiKey」的類型「的UIViewController *」 屬性「requestPremision」的對象未找到沒有找到'UIViewController *'類型的對象 我更新了問題 – user63898

+0

對不起,在我的示例中,我將viewController聲明爲UIViewController而不是TAFBLoginDialogViewController,這就是爲什麼你會得到屬性不存在的錯誤。我更新了這個例子。 – Brandon

+0

你是男人!謝謝! – user63898