Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add title and Done button on toolbar in a modal view
    primarykey
    data
    text
    <p>I try to present a modal view (InfoViewController) from a navigation view controller(DateViewController).</p> <p>I add a toolbar on top of InfoViewContoller's view. Now I want to add a title "Info" and a "Done" button on the toolbar.(The Done button will perform the infoDismissAction method)</p> <p>Can anyone give me som tips? Thanks a lot!</p> <p>Here's code of DateViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "InfoViewController.h" @interface DateViewController : UIViewController { InfoViewController *infoViewController; } @property (nonatomic, retain) InfoViewController *infoViewController; @end </code></pre> <p>DateViewController.m</p> <pre><code>- (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]; } - (void)dealloc{ if (self.infoViewController != nil) { [infoViewController release]; } [super dealloc]; } - (void)viewDidLoad{ self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Info" style:UIBarButtonSystemItemPlay target:self action:@selector(modalViewAction:)] autorelease]; [modalBarButtonItem release]; [super viewDidLoad]; } </code></pre> <p>Here's InfoViewController.m</p> <pre><code>- (IBAction)infoDismissAction:(id)sender{ [self.parentViewController dismissModalViewControllerAnimated:YES]; } - (void)viewDidLoad { UIToolbar *toolBar; toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; toolBar.frame = CGRectMake(0, 0, 320, 50); toolBar.barStyle = UIBarStyleDefault; [toolBar sizeToFit]; [self.view addSubview:toolBar]; [toolBar release]; [backButton release]; [super viewDidLoad]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload