2011-02-06 85 views
1

我正在使用cocos2d,並且我想要一個UIAlertView彈出如果CCMenuItemFont文本被點擊。我可以讓alertView彈出,但是我想要在文本被點擊之後。這裏是我的代碼 INITUIAlertView如果CCMenuItemFont(文本)挖掘

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

的編碼是錯誤的。它不應該是顯示警報和攻絲在一起..而且你必須在menuitemFont添加到CCMenu ..

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 2011-02-08 00:17:22