簡體   English   中英

來自AppDelegate的Xcode更新視圖控制器UIImage

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM