无法确定的 UISharedApplication bug
-(void) setupMyLocation {
NSArray *viewControllerArray = [navigationUpdateFromDetail.navigationController viewControllers];
NSUInteger parentViewControllerIndex = [viewControllerArray count] - 2;
NSLog(@"Parent view controller: %@", [viewControllerArray objectAtIndex:parentViewControllerIndex]);
switch(parentViewControllerIndex){
case 0:
self.myLocation = navigationUpdateFromDetail.currentLocation;
break;
case 1:
YANAVAppDelegate *currentObject = (YANAVAppDelegate*)[[UIApplication sharedApplication]delegate];
// self.myLocation = currentObject.givenLocation;
break;
default: break;
}
}
我似乎无法弄清楚为什么我不断收到错误“在 YANAVAppdelegate 之前需要表达式”。
我似乎无法弄清楚为什么这不能编译。任何意见表示赞赏..提前致谢。
-(void) setupMyLocation {
NSArray *viewControllerArray = [navigationUpdateFromDetail.navigationController viewControllers];
NSUInteger parentViewControllerIndex = [viewControllerArray count] - 2;
NSLog(@"Parent view controller: %@", [viewControllerArray objectAtIndex:parentViewControllerIndex]);
switch(parentViewControllerIndex){
case 0:
self.myLocation = navigationUpdateFromDetail.currentLocation;
break;
case 1:
YANAVAppDelegate *currentObject = (YANAVAppDelegate*)[[UIApplication sharedApplication]delegate];
// self.myLocation = currentObject.givenLocation;
break;
default: break;
}
}
I cannot seem to figure out why i keep getting an error "expecting expression before YANAVAppdelegate".
I cannot seem to put my finger on why this will not compile. any input is appreciated.. thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要在 switch 语句内定义变量 (currentObject)。
Don't define the variable (currentObject) inside the switch statement.
如果需要在 case 语句中定义变量,可以使用大括号来完成(顺便说一句,这种技术也适用于 C++):
一位 C++ 大师曾经向我解释过,这为您的变量提供了一个上下文堆栈,以便它们存在, switch / case 语句不会自动提供。如果您在该上下文中创建任何对象,请记住删除/释放对象,否则很容易导致内存泄漏。
我个人总是在我的案例陈述中使用大括号,如果你问我;)你永远不知道将来是否需要它们,它使事情更容易理解。
If you need to define a variable inside a case statement, you can do it using curly brackets (this technique also works in C++, by the way):
A C++ guru explained me once that this gives your variables a context stack for them to exist, which the switch / case statement does not provide automatically. Remember to delete / release objects if you create any in that context, otherwise it's an easy way to have a memory leak.
I personally always use curly brackets in my case statements, if you ask me ;) you never know if in the future you'll need them, it makes things easier to understand.