![](/img/trans.png)
[英]Update label in another View Controller from the appDelegate
[英]Xcode Update View Controller UIImage from AppDelegate
我想从ViewController.m
AppDelegate
调用一个函数。 我将很好地访问该功能,但是View Controller功能无法正常工作。
在AppDelegate.m
文件中,我有:
#import "AppDelegate.h"
#import "UserList.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *UserName = [NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"from"]];
if (application.applicationState == UIApplicationStateActive)
{
UserList *ul = [[UserList alloc] init];
[ul AddUserWhenNotExists:UserName];
}
}
视图控制器的UserList.m
文件:
#import "UserList.h"
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)accessFromAppDelegate
{
UIImageView *setting =[[UIImageView alloc] initWithFrame:CGRectMake(0,20,61,60)];
setting.image=[UIImage imageNamed:@"setting_icon.png"];
[setting setUserInteractionEnabled:YES];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SettingClick:)];
[singleTap setNumberOfTapsRequired:1];
[setting addGestureRecognizer:singleTap];
[self.view addSubview:setting];
}
在视图控制器的UserList
,不附加setting_icon.png
。 我的代码错了吗? 请帮忙。
谢谢你的时间。
您可能要使用NSNotificationCenter: https : //developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsnotificationcenter_Class/Reference/Reference.html
您可以使用它来告诉UIViewController什么时候发生。 这是一些示例代码: https : //stackoverflow.com/a/9127852/2661880
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.