完了ボタンは、ModalViewControllerを却下していません
-
28-10-2019 - |
質問
完了]ボタンをクリックすると、ModalViewControllerを却下していません。 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を却下していません。 MainViewController HおよびMファイルに何かを追加することになっていますか。 MainViewControllerファイルに何かが欠けている場合は、私を助けてください。
手伝ってくれてありがとう、
解決
-(void)dismissView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
ただし、デリゲートメソッドでコントローラーを却下したい場合は、最初にInfoViewControllerにデリゲートを設定する必要があります。次に、DelegateメソッドでInfoViewControllerオブジェクトを使用して却下する必要があります。
所属していません StackOverflow