帮助我在 Objective-C 的 UIViewController 的应用程序委托(delegate)数组中添加对象我想我做错了,在这方面帮助我
我想在 View Controller 的应用程序委托(delegate)数组中添加对象
在appdelegate.h中
@property (nonatomic, retain) NSMutableArray *sharedArray;
在 appdelegate.m 中
@implementation AppDelegate
@synthesize sharedArray;
在 didfinishlaunching 中
self.sharedArray = [[NSMutableArray alloc] init];
在 View Controller 中
@interface ViewController () {
UIApplication *appDelegate;
viewcontroller
viewdidload
内部
appDelegate = [[UIApplication sharedApplication] delegate];
[appdelegate.sharedArray addObject:array];
最佳答案
您的代码很好且正确,但是您需要在附加对象之前初始化数组的内存
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self. sharedArray = [NSMutableArray array];
return YES;
}
最后调用方法为
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.sharedArray addObject:array];
最后导入标题
#import "AppDelegate.h"
关于ios - 从 Objective-C iOS 中的 View Controller 在应用程序委托(delegate)数组中添加对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49773206/