Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:06:11+00:00 2026-05-26T08:06:11+00:00

In FirstViewController I declare a button which present the modal view InfoViewController. In InfoViewController,

  • 0

In “FirstViewController” I declare a button which present the modal view “InfoViewController”.

In “InfoViewController”, I declare a toolbar with a “modalViewButton” UIButton which dismiss the modal view. But the “OK” UIButton doesn’t work. I don’t know why.

Here’s FirstViewController.h

#import <UIKit/UIKit.h>
#import "InfoViewController.h"

@interface FirstViewController : UIViewController 
{
    InfoViewController *infoViewController; 
}

@property (nonatomic, retain) InfoViewController *infoViewController;
@end

Here’s FirstViewController.m

#import "FirstViewController.h"
@implementation FirstViewController
@synthesize infoViewController;

- (IBAction)modalViewAction:(id)sender
{  
    if (self.infoViewController == nil)
        self.infoViewController = [[[InfoViewController alloc] initWithNibName:
                                NSStringFromClass([InfoViewController class]) bundle:nil] autorelease];
    [self presentModalViewController:self.infoViewController animated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

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

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];   
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIButton* modalViewButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
    [modalViewButton addTarget:self 
                    action:@selector(modalViewAction:) 
          forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:modalViewButton];
    self.navigationItem.leftBarButtonItem = modalBarButtonItem;
    [modalBarButtonItem release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Here’s InfoViewController.h

#import <UIKit/UIKit.h>     
@interface InfoViewController : UIViewController 
{

}
-(IBAction)infoDismissAction:(id)sender;
@end

Here’s the InfoViewController.m

#import "InfoViewController.h"

@implementation InfoViewController

- (IBAction)infoDismissAction:(id)sender
{
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {

    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}    

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    UILabel *infoLabel = [[UILabel alloc] init];
    infoLabel.frame = CGRectMake(50, 100, 100, 40);     
    infoLabel.textAlignment = UITextAlignmentCenter;        
    infoLabel.text = @"About";      
    [self.view addSubview:infoLabel];       

    UIToolbar *toolBar;
    toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    toolBar.frame = CGRectMake(0, 0, 320, 50);
    toolBar.barStyle = UIBarStyleDefault;
    [toolBar sizeToFit];    

    UIBarButtonItem *flexibleSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:                               UIBarButtonSystemItemFlexibleSpace 
                                                                                target:nil 
                                                                                        action:nil] autorelease];

    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"OK" 
                                                                   style:UIBarButtonItemStyleBordered 
                                                              target:self 
                                                              action:@selector(infoDismissAction:)];

    UIBarButtonItem* infoTitle = [[UIBarButtonItem alloc] initWithTitle:@"About" 
                                                              style:UIBarButtonItemStylePlain 
                                                             target:self action:nil];

    NSArray *barButtons = [[NSArray alloc] initWithObjects:flexibleSpace,flexibleSpace,infoTitle,flexibleSpace,doneButton,nil];

    [toolBar setItems:barButtons];

    [self.view addSubview:toolBar]; 

    [toolBar release];
    [infoTitle release];
    [doneButton release];
    [barButtons release];
    [infoLabel release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:06:12+00:00Added an answer on May 26, 2026 at 8:06 am

    I would solve this issue with a delegate method.

    First make a protocol in your modalViewController

    @protocol ModalViewDelegate <NSObject>
    
     - (void)didDismissModalView;
    
    @end
    

    And set a delegate property in the same modalVC:

    id<ModalViewDelegate> dismissDelegate;
    

    Then make a buttonActionMethod that calls the delegate in the modalVC:

    - (void)methodCalledByButton:(id)sender 
    {
        // Call the delegate to dismiss the modal view
        [self.dismissDelegate didDismissModalView];
    }
    

    Now your modalVC is done you have to prepare the mainVC calling the modalVC:
    You have to make your MainViewController comform to the delegate:

    @interface MainViewController : UIViewController <ModalViewDelegate>
    

    At the place you alloc your ModalViewController you have to set the delegate property you made in your modalViewController:

    self.myModalViewController.dismissDelegate = self;
    

    Now the MainViewController listens to the delegate and the only thing you need to do is implement the delegateMethod.

    -(void)didDismissModalView
    {
        [self dismissModalViewControllerAnimated:YES];
    }
    

    Now your ModalVC will dismiss on a buttonpress (at least when you call the method properly)

    Hope this all makes sense.
    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I accidentally deleted my firstviewcontroller.m file which is for a view that has a
I have MainMenuViewController with button which action is - (IBAction) goToFirstView { FirstViewController *fvc
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
I have two view controllers: firstViewController and secondViewController. On the firstViewController I have a
lets say i have two view controllers, firstViewController and secondViewController. The firstViewController is supposed
everyone, i have no idea why this doesn't work hopefully someone here can help
So i have two view controller in FirstViewController and SecondViewController in FirstViewController NSMutableArray *array;
I have a first view which is the log in screen. After the user
Hi i have two view controller: FirstViewController and SecondViewController FirstViewController.h #import <UIKit/UIKit.h> @interface FirstViewController:
4 files for 2 view controllers, firstviewcontroller and MyOverlayView. MyOverlayView just receives touches and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.