【发布时间】:2014-07-26 06:22:38
【问题描述】:
我确实搜索过,但网上没有找到艾米的答案。
我在故事板主 UITableViewController 中创建了一个名为 A 的简单按钮。
和另一个名为 B 的 ViewController 具有 webView 和关闭按钮。
没有以任何形式连接到主 UITableViewController A
现在我喜欢打开 B viewController form A 然后用它自己的关闭按钮关闭 B ViewController。
但是我尝试过的 B 视图控制器是黑色和空白的。
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 =@"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 B 和调用:
[self.LoginDialogViewController checkLoginRequired:@"tst"];
应该显示 ViewController B 但它所做的一切都显示黑屏。
【问题讨论】:
标签: objective-c ios7 xcode5 xcode-storyboard