完成按钮不会关闭 modalviewcontroller

发布于 2024-12-27 01:02:35 字数 1772 浏览 0 评论 0原文

当我单击“完成”按钮时,它不会关闭 modalviewcontroller 在我的情况下它是 infoviewcontroller。我是否应该在 mainviewcontroller h 和 m 文件中添加一些内容?

在 Infoviewcontroller.h 中

#import <UIKit/UIKit.h>

@protocol ModalViewDelegate <NSObject>

-(void) dismissModalView;

@end

@interface Infoviewcontroller : UIViewController <UITextViewDelegate>

{
id<ModalViewDelegate>dismissDelegate;
UITextView *textView;
UINavigationBar *navBar;

}

@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, assign) UINavigationBar *navBar;
@property (nonatomic, assign) id<ModalViewDelegate>dismissDelegate;

@end

在 Infoviewcontroller.m 中

#import "Infoviewcontroller.h"
#import <QuartzCore/QuartzCore.h>


@implementation Infoviewcontroller

@synthesize textView;
@synthesize navBar;
@synthesize dismissDelegate;



-(void)dealloc
{
[textView release];
[navBar release];
[super dealloc];
}

- (void) viewDidLoad
{
  [super viewDidLoad];

    UIButton* backButton = [UIButton buttonWithType:101]; 
    [backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setTitle:@"Done" forState:UIControlStateNormal];

    // create button item
    UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    // add the button to navigation bar
    self.navigationItem.leftBarButtonItem = backItem;
    [backItem release];

 -(void)dismissView:(id)sender
{
    //Make the delegate close the modal
    [self.dismissDelegate dismissModalView];

}

当我单击“完成”按钮时,它不会关闭 modalviewcontroller 在我的情况下它是 infoviewcontroller。我是否应该在 mainviewcontroller h 和 m 文件中添加一些内容?如果我在 mainviewcontroller 文件中遗漏了某些内容,请帮助我。

感谢您的帮助,

When i click on the done button it is not dismissing modalviewcontroller in my case it is infoviewcontroller. Am i supposed to add something in mainviewcontroller h and m file.

In the Infoviewcontroller.h

#import <UIKit/UIKit.h>

@protocol ModalViewDelegate <NSObject>

-(void) dismissModalView;

@end

@interface Infoviewcontroller : UIViewController <UITextViewDelegate>

{
id<ModalViewDelegate>dismissDelegate;
UITextView *textView;
UINavigationBar *navBar;

}

@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, assign) UINavigationBar *navBar;
@property (nonatomic, assign) id<ModalViewDelegate>dismissDelegate;

@end

In the Infoviewcontroller.m

#import "Infoviewcontroller.h"
#import <QuartzCore/QuartzCore.h>


@implementation Infoviewcontroller

@synthesize textView;
@synthesize navBar;
@synthesize dismissDelegate;



-(void)dealloc
{
[textView release];
[navBar release];
[super dealloc];
}

- (void) viewDidLoad
{
  [super viewDidLoad];

    UIButton* backButton = [UIButton buttonWithType:101]; 
    [backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setTitle:@"Done" forState:UIControlStateNormal];

    // create button item
    UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    // add the button to navigation bar
    self.navigationItem.leftBarButtonItem = backItem;
    [backItem release];

 -(void)dismissView:(id)sender
{
    //Make the delegate close the modal
    [self.dismissDelegate dismissModalView];

}

When i click on the done button it is not dismissing modalviewcontroller in my case it is infoviewcontroller. Am i supposed to add something in mainviewcontroller h and m file. Please help me if i am missing some thing in the mainviewcontroller files.

Thanks for help,

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

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

发布评论

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

评论(1

榆西 2025-01-03 01:02:35
-(void)dismissView:(id)sender
{
       [self dismissModalViewControllerAnimated:YES];

}

但是如果你想在委托方法中关闭控制器,那么你首先必须在 infoviewController 中设置委托,然后在委托方法中使用 infoviewController 对象来关闭它。

-(void)dismissView:(id)sender
{
       [self dismissModalViewControllerAnimated:YES];

}

but if you want to dismiss the controller in the delegate method then you first have to set the delegate in infoviewController then in the delegate method use the infoviewController object to dismiss it .

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