简体   繁体   English

UIPicker和UIActionsheet不再适用于iOS7

[英]UIPicker and UIActionsheet no longer working iOS7

Hi My UI Picker no longer works on iOS7, it pops up but it is blank. Hi My UI Picker不再在iOS7上运行,它会弹出但为空。 Only happened on iOS7. 仅发生在iOS7上。

//picker
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
animationsLabel.text = [optionsArray objectAtIndex:[picker selectedRowInComponent:0]];

if (pickerView==animationsPicker) {
    animationsLabel.text = [optionsArray objectAtIndex:[animationsPicker selectedRowInComponent:0]];
}

}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [optionsArray count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
   return [optionsArray objectAtIndex:row];
   NSLog(@"title options array %lu",(unsigned long)optionsArray.count);
}

And the action: 动作:

-(IBAction)animationActionSheet:(id)sender {

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

[selectPopup showInView:self.view];

optionsArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"6",@"5",@"7",@"8",@"9", nil];

// Create picker
animationsPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 160, 320, 100)];
animationsPicker.showsSelectionIndicator = YES;
[self.view addSubview:animationsPicker];
animationsPicker.delegate = self;
animationsPicker.dataSource = self;
[selectPopup addSubview:animationsPicker];

// Animate picker opening
[UIView beginAnimations:nil context:nil];
[selectPopup setBounds:CGRectMake(0, 0, 320, 485)];
[UIView commitAnimations];
}

This is what I have tried so far. 到目前为止,这是我尝试过的。 There was never a problem displaying the picker in the an Action sheet before, but now it is blank. 以前在动作表中显示选择器从来没有问题,但是现在它是空白。 Im wondering did anyone else come across this problem, or can you see any errors? 我想知道是否还有其他人遇到此问题,或者您能看到任何错误吗? I printed everything to do with the picker. 我打印了与选择器有关的所有内容。

I was told that putting pickers in Action Sheets was non-standard. 有人告诉我,将选择器放入操作表中是非标准的。 I never had any problems doing this in iOS 6, but in iOS 7, I got errors. 我在iOS 6中从未遇到任何问题,但是在iOS 7中,我遇到了错误。 I switched to UIView instead of action sheets for my pickers and it works fine. 我为选择器切换到了UIView而不是操作表,它可以正常工作。 I hope this helps. 我希望这有帮助。

Adding subviews is not recommended for the action sheet, per documentation. 根据文档,不建议在操作表中添加子视图。

"Subclassing Notes UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:." “子类化Notes UIActionSheet并非旨在进行子类化,也不应在其层次结构中添加视图。如果您需要呈现的工作表比UIActionSheet API提供的自定义项更多,则可以创建自己的工作表并使用presentViewController:animated方式呈现它:completion:。”

Apple is reinforcing their usage for Action Sheets....and they upped the ante for this to work in iOS 7, which means you have to code around it. 苹果正在加强其对Action Sheets的使用...。他们为此增加了赌注,以便在iOS 7中正常工作,这意味着您必须对其进行编码。

Check out this project I made. 看看我做的这个项目。 It's practically the same thing as having a picker inside an action sheet https://github.com/DiscoverPioneer/PickerSlider 这实际上与在操作表中放置一个选择器https://github.com/DiscoverPioneer/PickerSlider一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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