我在我的咖啡订单应用程序的某个阶段,我从DetailViewController弹出UIAlertView,询问是/否继续。 '是'转到下一个View Controller,这很好,但是没有'也转到相同的视图控制器,但我只是想让它返回到DetailViewController,为用户提供更改其顺序的选项。我可以在代码中看到使用if语句,但是下面的代码提供了" Unexpected接口名称' DetailViewController':期望表达式消息" 我是新手,一个学生在学习,虽然有教程,但在我的第二个代码中有一段代码,如果'根据本网站上的一些解决方案,buttonIndex == 1的语句应该是正确的,但出于某种原因,我在这里遗漏了一些东西。我使用XCode v7.0.1,也很难找到这个版本的最新解决方案。 (注意我知道UIAlertView已弃用的代码,但它正在运行)
这是代码,感谢一些帮助:
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize YourOrder;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.DetailTitle.text = _DetailModule[0];
self.DetailDescription.text = _DetailModule[1];
self.DetailImageView.image = [UIImage imageNamed:_DetailModule[2]];
self.navigationItem.title = _DetailModule[0];
self.YourOrder.text = @"";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)addItem:(id)sender {
self.YourOrder.text = [NSString stringWithFormat:@"%@ \n %@",
self.YourOrder.text, [sender currentTitle]];
}
- (IBAction)alertView:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send Order" message:@"Are you happy with your order?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked Yes
if (buttonIndex == 0)
{
// do something here...
}
// the user clicked No - need to write code to return a 'no' click to the DetailViewController to try again.
if (buttonIndex == 1)
{
[self presentViewController:DetailViewController animated:YES completion:nil];
}
}
@end
我也尝试过:
if (buttonIndex == 1)
{
DetailViewController *detailView = [[DetailViewController alloc] init];
[self presentViewController:detailView animated:YES completion:nil];
}
但它仍然会转到相同的View控制器,我看到"警告:尝试显示其视图不在窗口层次结构中!"错误信息。