Invalid context error on iOS 7 when adding a UIPickerView inside a UIActionSheet?

前端 未结 3 571
悲哀的现实
悲哀的现实 2021-01-05 00:14

I have an UIPickerView inside an UIActionSheet and have done that in a way suggested by many others here at SO:

Add UIPickerView & a Button in Action sheet - How

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 00:41

    A workaround for this 'invalid context 0x0' warning is to init the UIActionSheet with a non nil title (non-nil buttons also resolve the error but result in visual artefacts).

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" 
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];
    

    You will then need to adjust the actionsheet's frame for it to position properly in both iOS7 and previous versions (make sure to do this after the showInView method).

    CGRect newFrame = actionSheet.frame;
    newFrame = self.view.bounds.size.height - myCustomPicker.frame.size.height;
    newFrame = myCustomPicker.frame.size.height;
    actionSheet.frame = newFrame;
    

提交回复
热议问题