【问题标题】:Use boolean to check state of application objective c使用布尔值检查应用程序目标 c 的状态
【发布时间】:2011-12-18 14:19:21
【问题描述】:

我不知道问题是否格式正确。所以我在启动应用程序时显示了一个 uialertview 30 秒。在此 uialertview 中有一个“确定”按钮,用户可以单击该按钮并释放警报。如果用户在 30 秒内未单击此按钮,则会释放警报。 这是代码..

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" 
                                                message:@"Welcome!" 
                                               delegate:nil 
                                      cancelButtonTitle:@"OK" 
                                      otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];

dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*30.0);
dispatch_after(delay, dispatch_get_main_queue(), ^{
[alert release];

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {

}

所以我必须用一个布尔值来实现控件来检查用户是否点击确定... 你能帮我吗?我是目标 c 的新手 :) 谢谢!

【问题讨论】:

    标签: iphone objective-c boolean uialertview


    【解决方案1】:

    如下所示显示您的警报视图: 假设 isD 为 BOOL 值(在 .h 文件中声明为类成员)

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" 
                                                    message:@"Welcome!" 
                                                   delegate:self
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];
    [alert setTag:1000];
    [alert show];
    isD = NO;
    
    dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*5.0);
    dispatch_after(delay, dispatch_get_main_queue(), ^{
    
        if (!isD) {
            [alert dismissWithClickedButtonIndex:0 animated:YES];
        }
    });
    [alert release];
    

    并编写 UIAlertViewDelegate 方法

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        if( alertView.tag == 1000 )
        {
            isD = YES;
        }
    }
    

    【讨论】:

    • isD = YES 有一个警告.. -> 警告:语义问题:从 'BOOL'(又名 'signed字符')
    • BOOL 不是指针。你是如何在头文件中声明的?布尔*是D;或 BOOL 是 D;第二个是正确的。
    猜你喜欢
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 2012-12-17
    相关资源
    最近更新 更多