English 中文(简体)
• 如何在模式观点中添加标题和Done button on toolbar
原标题:How to add title and Done button on toolbar in a modal view

我试图从一个导航观察控制员(DateViewController)提出一个模式。

我在“InfoContoller”的意见上添加了一个工具。 现在我想在工具栏上添加一个标题“Info”和“Done”纽扣。 多纽纽纽州将采用信息促进发展的行动方法。

谁能给我 so? 感谢很多!

页: 1

#import <UIKit/UIKit.h>
#import "InfoViewController.h"
@interface DateViewController : UIViewController 
{
    InfoViewController *infoViewController;
}
@property (nonatomic, retain) InfoViewController *infoViewController;
@end

DateViewController.m

- (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];
}

Here s InfoViewController.m

- (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];
}
最佳回答

引证该法典。

- (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];      
UIBarButtonItem *flexibleSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
UIBarButtonItem *infoButton = [[[UIBarButtonItem alloc] initWithTitle:@"INFO" style:UIBarButtonItemStyleBordered target:self action:@selector(InfoAction:)] autorelease];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"DONE" style:UIBarButtonItemStyleBordered target:self action:@selector(doneAction:)];


            NSArray *barButton  =   [[NSArray alloc] initWithObjects:flexibleSpace,infoButton,flexibleSpace,doneButton,nil];
            [toolBar setItems:barButton];

        [self.view addSubview:toolBar];
        [toolBar release];
        [barButton release];
        barButton = nil;
        [super viewDidLoad];

}
问题回答

I d recommend setting up another UINavigationController with your InfoViewController and present the navigation controller as your modal view.

回答你想要填写UIToolbar一样的问题:

- (void)viewDidLoad {
  [super 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];

  UIBarButtonItem* bbiInfo = [[UIBarButtonItem alloc] initWithTitle:@"Info" style:UIBarButtonItemStyleBordered target:self action:@selector(tappedInfoButton)];
  UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  UIBarButtonItem* bbiDone = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(tappedDoneButton)];
  NSArray* items = [[NSArray alloc] initWithObjects:bbiInfo, flexibleSpace, bbiDone, nil];
  [toolBar setItems:items];

  [items release];
  [bbiInfo release];
  [flexibleSpace release];
  [bbiDone release];
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签