简体   繁体   中英

In UIActionSheet the cancel button not showing for iphone?

In my application when I click on change image it's asks UIActionsheet with three actions take photo ,choose from library and cancel.Take photo ,choose from library are showing but cancel didn't showing where is the problem. this is my code

    - (void)viewDidLoad
{
         [super viewDidLoad];
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..."
        delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
        actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
        [actionSheet showInView:self.view];
}

这是因为...我认为您使用的是默认的视图大小-Retina 4全屏作为视图大小...只需尝试从属性检查器将视图大小更改为Retina 3.5全屏... !!!

try this one...

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." 
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:@"Cancel"
                                                otherButtonTitles:@"Take Photo", @"Choose from library", nil];

    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];

You may want to take a look at the alternative methods for presenting an action sheet in the class reference . However, you may want to try using one of the following (if you have a toolbar)

– showFromBarButtonItem:animated:
– showFromToolbar:

Additionally, using the following

actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

will only ever result in the action sheets style being default.

Please refer this link .

And you can refer below code also, it may help you:

(void)viewDidLoad
    {

    UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil];
    [actionSheet showInView:self.view];

    }

Since your problem is not with your code. Maybe you are using the wrong method to display your UIActionSheet.

A UIActionSheet can be displayed with following methods:

– showFromTabBar:
– showFromToolbar:
– showInView:
– showFromBarButtonItem:animated:
– showFromRect:inView:animated:

take a look at Apple's UIActionSheet reference .

Since you use a TabBar, the Cancel button may also be below. I would test that too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM