导航栏“返回”关闭模态视图的按钮

发布于 2024-09-11 07:37:17 字数 1614 浏览 10 评论 0原文

我正在尝试为我的应用程序中的网站创建类似自己的“adBanner”的内容。

横幅是一个带有图像的按钮,实际上是横幅图形。

[_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];

翻转视图的函数

- (IBAction)showWebView:(id)sender {    

XLog ("Button Clicked");

WebViewController *_webViewController = [[WebViewController alloc] init];


_webViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:_webViewController animated:YES];  

}

这是我在 _webViewController 中

编写了一个导航栏

我想显示一个带有 url 的 UIWebView 首先,我用标题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];

:现在我创建了一个后退按钮

[ navBar showButtonsWithLeftTitle: @"Zurück" rightTitle:nil leftBack: YES];

我的问题是如何制作我的后退按钮再次关闭模态视图? 或者我该如何设置动作?谢谢你的帮助

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲墙角沉默 2024-09-18 07:37:17

如果您之后使用此代码,那么它将起作用。

    navBar.topItem.leftBarButtonItem =[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonItemToDismissModal)];


-(void)backButtonItemToDismissModal{

    [self dismissModalViewControllerAnimated:YES];

}

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];

}
如果没有你 2024-09-18 07:37:17

如果你想使用模态视图控制器,那么你可以使用 WebViewController 类的missModalViewController 方法来关闭它。

另一种方法是使用 UINavigationController。您可以检查示例控制器。

要使左按钮工作,您还应该实现

- (void)navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button

方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文