我需要一个按钮来弹出带有操作的 UIAlertView。
一旦警报弹出,它需要有 1 个按钮来取消并保持在同一页面上,以及 1 个按钮将您链接到另一个 ViewController。
这是我从一些论坛上拼凑出来的,但我不知道自己在做什么,它给了我大约 9 条错误消息。请帮忙!
-(IBAction)Alert:(id)sender {
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Warning! By entering the Tutorial, all data will be lost. Are you sure you want to continue?"
delegate:self
cancelButtonTitle:@"Return to Data Collection"
otherButtonTitles:@"Continue", nil];
[Alert Show];
[Alert Release];
}
- (void)Alert:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(Alert.tag==0) {
if(buttonIndex == 1)//OK button pressed
{
Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Info animated:YES];
}
第一个代码框有效,因此当我在主屏幕上按下一个按钮时,会弹出一个带有 2 个按钮的警报。
但是,我无法获得第二个按钮以将我链接到下一个 ViewController。
最佳答案
Objective-C 区分大小写。
[Alert show]; [Alert release];
和
- (void)alertView:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex
(你觉得怎么样,重命名方法还能行吗???)
删除
if(Alert.tag==0) {
为什么不在这里传递 nib 文件的名称:
<Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];
请遵守编码约定。对象以驼峰命名。
结论
给你一本好书或视频,让你从头开始学习。 Some resources这样做。
关于objective-c - 带有链接备用 ViewController 的 Button 的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8996990/