我有一个布尔变量需要在我的 appDelegate 中访问,但我不知道该怎么做。我试图导入另一个视图控制器然后实现它,但它出现了一个 Apple Mach-O 链接器 (id) 错误,显示“链接器命令失败,退出代码为 1”。我对应用程序开发相当陌生,所以请用简单的术语解释一下。我正在使用情节提要,因此无法将 xib/nib 文件与我的代码结合使用。
问问题
1244 次
2 回答
0
Yon 可以在 MyAppDelegate.h 中声明一个属性:
@property (strong, nonatomic) NSString *myString;
然后你可以在你的 ViewController 中访问它:
#import "MyAppDelegate.h"
...
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%@", appDelegate.myString);
于 2012-08-30T15:19:33.037 回答
0
访问 AppDelegate.h 中的 Bool 变量声明到任何其他 UIViewController..
1) 在 AppDelegate.h
@property (nonatomic)BOOL myBool;
2) 在 AppDelegate.m
@synthesize myBool;
3) 访问任何其他 UIViewController 中的 myBool 变量
#define myAppDelegate [[UIApplication sharedApplication]delegate]
// define above line below @implementation XyzViewController
if (((AppDelegate *)myAppDelegate).myBool)
{
//implement logic
}
else
{
}
于 2014-12-09T12:47:54.543 回答