iOS actionsheet Showinview causes crash resolution

Source: Internet
Author: User

If you call the Add Actionsheet feature in your code

1Uiactionsheet *actionsheet =[[Uiactionsheet alloc]2 Initwithtitle:nil3                                   Delegate: Self4 Cancelbuttontitle:asbuttontitlecancel5 Destructivebuttontitle:nil6 Otherbuttontitles:asbuttontitlecamera, Asbuttontitlelibrary,nil];7Actionsheet.actionsheetstyle =Uiactionsheetstyleblackopaque;8[Actionsheet ShowInView:controller.view];

Normally, it can be paged out.

This selection menu

If the Controller.view is not added to the window, the system will crash with an error.

The error content is as follows:

Terminating app due to uncaught exception ' nsinvalidargumentexception ', Reason: ' Sheet can isn't be presented because the VI EW isn't in a window: <UIView:0xce7df00; frame = (0 0; 320 480); AutoResize = RM+BM; Layer = <CALayer:0xce51bb0>> '

******

This is because the controller's viewdidload joined the Actionview Showinview method, but this time in fact, the view has not joined the window, does not meet the requirements of actionsheet.

There are other workarounds on the web, say add to window, or check if window's subviews already contains the current view

I am not very recommended to use the above method, not solve my problem.

Later changed in Viewdidappear to call Actionview Showinview, this time the view has been added to the window, there is no such problem.

1- (void) Viewdidload {2 [Super Viewdidload];3     //additional setup after loading the view, typically from a nib.4     5     //originally added Actionsheet here and Showinview:self.view6     7 }8 9- (void) Viewdidappear: (BOOL) Animated {Ten      One   //add Actionsheet and Showinview:self.view here after the modification A}

Reference information:

http://blog.csdn.net/hwak_07/article/details/27107319

Http://stackoverflow.com/questions/18932544/nsinvalidargumentexception-reason-sheet-can-not-be-presented-because-the-vi

iOS actionsheet Showinview causes crash resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.