无法自行委托UIlAertView

时间:2016-09-20 06:08:32

标签: ios objective-c xcode

我想知道为什么我不能在这个功能上委托自己。

void foundJailbrokenDevice()
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Jailbrokeb=n Device Detected" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
            [alertView release];
}

- (void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
    UIApplication *app = [UIApplication sharedApplication];
    [app performSelector:@selector(suspend)];
    [NSThread sleepForTimeInterval:2.0];
    exit(0);
}
}

消息显示使用未声明的标识符“self”。我已经在我的.h文件中添加了UIAlertViewDelegate 我希望你们能帮助我,因为我是新手。 谢谢!

1 个答案:

答案 0 :(得分:0)

我认为您应该将函数foundJailbrokenDevice替换为以下类方法:

-(void) foundJailbrokenDevice
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Jailbrokeb=n Device Detected" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
}

并将foundJailbrokenDevice的使用情况替换为[self foundJailbrokenDevice]