Question

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,

Was it helpful?

Solution

-(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 .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top