2011-02-06 3 views
1

私はcocos2dを使用していますが、CCMenuItemFontのIFテキストをタップすると、UIAlertViewがポップアップします。私はalertViewをポップアップ表示させることができますが、テキストがタップされた後にそれを表示します。ここに私のコードは INITCCMenuItemFont(テキスト)がタップされた場合のUIAlertView

rate = [CCMenuItemFont itemFromString:@"Rate App" target:self selector:@selector(rateIsTapped:clickedButtonAtIndex:)]; 
    rate.position = ccp(240, 160); 
    [self addChild:rate]; 



-(void)rateTapped:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {  
rateView = [[UIAlertView alloc] initWithTitle:@"Like This App?" message:@"Rate it on the App Store!" delegate:self cancelButtonTitle:@"No thanks" otherButtonTitles:@"Sure, I'll rate it!", nil]; 
[rateView show]; 
[rateView autorelease]; 
[defaults setBool:YES forKey:@"rate"]; 

if (buttonIndex == 0) { 
    //[alertView collapse]; 
} 
if (buttonIndex == 1) { 
    NSURL *url = [NSURL URLWithString:@"LINK TO RATE IN APP STORE"]; 
    [[UIApplication sharedApplication] openURL:url]; 
} 

}

答えて

0

コードが間違っているが..それはショー警戒し、一緒にタップしてはならないのですそして、あなたはCCMenuにmenuitemFontを追加する必要があります。..

rate = [CCMenuItemFont itemFromString:@"Rate App" target:self selector:@selector(rateApp)]; 

CCMenu* menu = [CCMenu menuWithItems:rate, nil]; 
    menu.position = CGPointMake(-(size.width/2), size.height/2); 
    menu.tag = 100; 
    [self addChild:menu]; 


-(void)rateApp 
{ 
rateView = [[UIAlertView alloc] initWithTitle:@"Like This App?" message:@"Rate it on the App Store!" delegate:self cancelButtonTitle:@"No thanks" otherButtonTitles:@"Sure, I'll rate it!", nil]; 
[rateView show]; 
[rateView release]; 
[defaults setBool:Yes forKey:@"rate"]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
{ 
if (buttonIndex == 0) { 
//[alertView collapse]; 
} 

if (buttonIndex == 1) { 
    NSURL *url = [NSURL URLWithString:@"LINK TO RATE IN APP STORE"]; 
    [[UIApplication sharedApplication] openURL:url]; 
} 
} 
+0

シミュレータで[レートアプリケーション]をクリックしても、まだ何もしていません。しかし、クラッシュはありません – Joethemonkey101

+0

はい、私はそれを2つのメソッドに変更し、セレクタは1番目のメソッド(レート) – Joethemonkey101

+0

NSLogのレートアプリ関数で..それは関数を実行しましたか? – xuanweng