2011-08-03 12 views
0

プッシュ通知は、ApplePushNotificationAppDelegate.mでこれを実行します。iphone - プッシュ通知付きのラベルを変更できますか?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 

for (id key in userInfo) { 
    NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]); 
} 

ApplePushNotificationViewController *apns = [ApplePushNotificationViewController alloc]; 
NSLog(@"%@ changed", [apns labelchange]); 
} 

それはApplePushNotificationViewController.mに行くと、この

-(NSString *)labelchange{ 
label2.text = @"labelchanged"; 
return @"hi"; 
} 

を行い、コンソールの結果は私のiPhone上で

2011-08-03 18:20:56.501 ApplePushNotification[1473:707] key: acme1, value: bar 
2011-08-03 18:20:56.503 ApplePushNotification[1473:707] key: acme2, value: 42 
2011-08-03 18:20:56.505 ApplePushNotification[1473:707] hi changed 
2011-08-03 18:21:04.347 ApplePushNotification[1473:707] key: aps, value: { 
    alert = "You got a new denyapps!"; 
    badge = 5; 
    sound = "beep.wav"; 
} 

をラベルを変更することなく、このどのように私のプログラムの実行を来りますプログラムはlabel2.textを "labelchanged"に変更しませんか?

プッシュサービスを使用するには証明書を取得する必要がありますが、プロジェクトのリンクはここにあります。「PushMeBaby」はサーバーです。

http://dl.dropbox.com/u/12439052/ApplePushNotification.zip http://dl.dropbox.com/u/12439052/PushMeBaby.zip

感謝。

+0

?なぜそれがテキストを変更していないのですか? – Mahesh

答えて

0

を "labelchanged" されることはありませんですApplePushNotificationAppDelegate.h

#import <UIKit/UIKit.h> 

@class ApplePushNotificationViewController; 
@interface ApplePushNotificationAppDelegate : UIViewController { 
UIWindow *window; 
ApplePushNotificationViewController *viewController; 
} 

@property (nonatomic, assign) id <View1Delegate> delegate; 
@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UILabel *label; 
@property (nonatomic, retain) IBOutlet ApplePushNotificationViewController *viewController; 

@end 

ApplePushNotificationAppDelegate.mあなたLABEL2を初期化している

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
     viewController.label2.text = @"changetext"; 
} 
0

あなたのView Controllerでinitを呼び出すのではなく、allocだけです。

ApplePushNotificationViewController *apns = [ApplePushNotificationViewController alloc]; 

あなたのビューコントローラはすべてを初期化していません。あなたのビューコントローラコードで

、あなたは

-(NSString *)labelchange{ 
    label2.text = @"labelchanged"; 
    [self changelabel]; 
    return @"hi"; 
} 

としてlabelchangeメソッドを持っており、changelabel方法は

-(IBAction)changelabel{ 
label2.text = @"button"; 
} 

ので、ラベルのテキストが

+0

私はそれを初期化してもまだ動作していません –

+0

'ApplePushNotificationViewController.m'と 'ApplePushNotificationViewController.h'のコードを投稿してください –

+0

それはhttp://dl.dropbox.com/u/12439052/ApplePushNotification.zipの中にあります。 ... –

関連する問題