I´m trying to create something like an own "adBanner" for a website in my app.
The Banner is a Button with an image, which is actually the banner graphic.
[_adBanner setBackgroundImage:[UIImage imageNamed:@"test_banner.png"] forState:UIControlStateNormal];
_adBanner.opaque = YES;
[self.view addSubview:_adBanner];
[(UIButton*) _adBanner addTarget:self action:@selector(showWebView:) forControlEvents:UIControlEventTouchUpInside];
[_adBanner release];
here is my function for flipping the view
- (IBAction)showWebView:(id)sender {
XLog ("Button Clicked");
WebViewController *_webViewController = [[WebViewController alloc] init];
_webViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:_webViewController animated:YES];
}
in my _webViewController I want to show a UIWebView with an url
First I coded a Navigation Bar with Title
WebViewController.m :
// Setting Navigation Bar
CGRect navBarRect = CGRectMake(0.0f, 0.0f, 320.0f, 44.0f);
navBar = [ [ UINavigationBar alloc ] initWithFrame: CGRectMake(navBarRect.origin.x, navBarRect.origin.y, navBarRect.size.width, 45.0f)];
[ navBar setDelegate: self.view ];
[ self.view addSubview: navBar ];
[ navBar release];
// Setting TitleString
NSString* adClientTitleString = [ [ NSString alloc] initWithString:@"Client" ];
// Setting Title
[ navBar pushNavigationItem: [ [ UINavigationItem alloc ] initWithTitle:adClientTitleString ] ];
[ navBar setDelegate: self];
and now I created a back Button
[ navBar showButtonsWithLeftTitle: @"Zurück" rightTitle:nil leftBack: YES];
My question Is How I can make my back Button to dismiss the Modal View again ? Or how can I set the action ?? Thank You for helping
If you use this code after that then it will work.
navBar.topItem.leftBarButtonItem =[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonItemToDismissModal)];
-(void)backButtonItemToDismissModal{
[self dismissModalViewControllerAnimated:YES];
}
If you want to use modal view controller, then you can dismiss it with dismissModalViewController method of a WebViewController class.
Other way is to use UINavigationController. You may check examples for this controller.
To make left button work you should also implement
- (void)navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With