yos-social-objc
yos-social-objc copied to clipboard
Feature request: Cancel button
Some time user may accidentally tap the button, but once tapped, no cancel or close button, the only way to quite seems to end the task
How can I add a navigation bar with a cancel button without changing the original source?
I add a Cancel button with a navigationBar by my self
YahooSession.h
// ...
@property BOOL mobileWebAuthorization;
@property UIViewController *rootViewController;
@property (nonatomic, weak) UINavigationBar *navBar; // ADD THIS
@property UIWebView *authorizationWebView;
@property UIWebView *mobileAuthorizationWebView;
// ...
YahooSession.m
// ...
- (void)sendUserToAuthorization
{
// ...
// Use UIWebView
self.rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.rootViewController.view.frame.size.width, 64)];
navBar.barTintColor = [UIColor colorWithRed:0.251 green:0.000 blue:0.565 alpha:1];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(closeButtonTapped:)];
UINavigationItem *item = [[UINavigationItem alloc] init];
item.leftBarButtonItem = closeButton;
item.hidesBackButton = YES;
[navBar pushNavigationItem:item animated:NO];
self.authorizationWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, navBar.frame.size.height, self.rootViewController.view.frame.size.width, self.rootViewController.view.frame.size.height - navBar.frame.size.height)];
[self.authorizationWebView setDelegate:self];
NSURLRequest *request = [NSURLRequest requestWithURL:self.authorizationUrl];
[self.authorizationWebView loadRequest:request];
[self.rootViewController.view addSubview:navBar];
[self.rootViewController.view addSubview:self.authorizationWebView];
_navBar = navBar;
}
- (void)closeButtonTapped:(id)sender
{
[self.authorizationWebView removeFromSuperview];
[self.navBar removeFromSuperview];
self.authorizationWebView = nil;
self.rootViewController = nil;
}
// ...
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType
{
// ...
[webView removeFromSuperview];
[self.navBar removeFromSuperview]; // ADD THIS
self.authorizationWebView = nil;
self.rootViewController = nil;
// ...
// If desktop web page, close and resend authorization with mobile mask activated
[webView removeFromSuperview];
[self.navBar removeFromSuperview]; // ADD THIS
self.authorizationWebView = nil;
self.rootViewController = nil;
self.mobileWebAuthorization = YES;
[self sendUserToAuthorization];
}