如果CCMenuItemFont(文本)点击,则为UIAlertView

时间:2011-02-06 19:24:55

标签: iphone text cocos2d-iphone uialertview

我正在使用cocos2d,我想要一个UIAlertView弹出CCMenuItemFont的IF文本被点击。我可以弹出alertView,但是我希望它在点击文本之后。这是我的代码 的 INIT

    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];
}

}

1 个答案:

答案 0 :(得分: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];
}
}