我正在研究一个原先为iOS 6编写的旧iOS应用程序,它有一些需要更改的UIActionSheets,所以我一直在努力将它们移动到UIAlertControllers ,使用UIAlertActions。这在iPad2模拟器上工作得非常好,但是当在iPad Air(我有权访问的唯一iPad)上测试时,我的UIAlertAction和UIAlertController在创建后直接变为零(在调试器中查看时,它接收创建指针,但是一旦它执行下一行,它将变为空)。这里是一个代码示例:为什么我的UIAlertActions在iPad上无效空气
//When hovering over the next line, alert has a pointer
UIAlertController* alert = [UIAlertController
alertControllerWithTitle:@"info"
message:@"testmessage"
preferredStyle:UIAlertControllerStyleActionSheet];
//alert pointer is now nil
//test pointer shows up
UIAlertAction* test= [UIAlertAction
actionWithTitle:@"I'm a Button"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
[alert dismissViewControllerAnimated: YES completion:nil];
}
];
//test pointer is nil, test2 pointer exists
UIAlertAction* test2 = [UIAlertAction
actionWithTitle:@"I'm a Button"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
[alert dismissViewControllerAnimated: YES completion:nil];
}
];
//test2 pointer is nil
[alert addAction:test];
[self presentViewController:alert animated:YES completion:nil]; //app crashes, because I'm trying to present a nil modal.
任何想法或帮助将大大appreaciated!
我有一个类似的问题,并通过将对象设置为@属性(强,非原子)而不是局部变量来解决它。 – rob180
您的iPad空中运行什么操作系统? –
@ rob180给了它一个镜头,但我仍然有同样的问题,出于某种原因,这些UI对象的指针在创建后直接变为零。 – Jet