English 中文(简体)
办公室 按纽芬兰语分列的观点
原标题:Dismiss ModalView Programmatically by done button
  • 时间:2012-01-13 16:22:56
  •  标签:
  • ios
  • iphone

我不得不点击已做的纽顿,以方案方式驳回模式调查。 我想UIButton优于BarButtonItem,添加ControlEvents TouchupInside

但有<条码>。 我混淆了应该使用什么样的纽子。

   UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];

[button addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];    

  UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                          target:self
                                                                          action:@selector(dismissViewaction:)] autorelease];
最佳回答

您最有可能使用<代码>。 UIButtonTypeRoundedRect或

With the custom type, you can add images for display.
You can try "stealing" these images from the UIBarButtonItem (image property defined in UIBarItem) and making the custom button look like the UIBarButtonSystemItemDone button

UIBarButtonItem * buttonForImage = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil                                                                       action:nil] autorelease];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button addTarget:self action:@selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];

[button setImage:buttonForImage.image forState:UIControlStateNormal];

引人瞩目。 在为UIButton树立形象时,该图不会根据contentMode对地国的大小加以扩大。 如果你希望图像符合<代码>contentMode中的财产,则使用setBackgroundImage: for State:

问题回答

I think the type of button doesn t matter. You have to assign an action 或 a select或 to the button. Something like this:

UIBarButtonItem *bttItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@select或(yourBttAction:)] aut或elease];

行动:

- (IBAction) yourBttAction:(id)sender
{
    NSLog(@"Done Button clicked");

    //do something
}

If the button is on the modalViewController, I usualy, f或 dismiss it, I use:

[self dismissModalViewControllerAnimated:(BOOL)];

//if you have a navigationController
[self.navigationController dismissModalViewControllerAnimated:(BOOL)];

But if you want to use a delegate to dismiss it, take a look at this tut或ial





相关问题
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, ...

热门标签