来自AppDelegate的xcode 5访问功能

时间:2014-07-03 02:43:40

标签: ios objective-c

UserList.m viewcontroller文件

#import "UserList.h"

- (void)viewDidLoad
{
    [super viewDidLoad];
}
- (void)accessFromAppDelegate
{
    NSLog(@"Access from appdelegate");
}

AppDelegate.m文件中

#import "AppDelegate.h"
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if (application.applicationState == UIApplicationStateActive) {
        //i want access accessFromAppDelegate on UserList.m in here
    }
}

如何从- (void)accessFromAppDelegate访问UseList.m的{​​{1}}? 我使用xcode 5,有时会发现这个问题,但无法解决。我是ios开发人员的新成员。

感谢您的光临。

2 个答案:

答案 0 :(得分:2)

在UserList.h中声明:

- (void)accessFromAppDelegate

将UserList.h导入AppDelegate。并称之为:

UserList *userList = [[UserList alloc] init];
[userList accessFromAppDelegate];

答案 1 :(得分:1)

首先,accessFromAppDelegate是一个实例方法,因此您必须拥有UserList类的实例。

UserList *ul = [[UserList alloc] init];
[ul accessFromAppDelegate];

=)