UIAlertView显示在模拟器上,但不显示在设备上

时间:2014-05-15 12:55:28

标签: ios objective-c uialertview

UIAlertView在模拟器中按预期工作,早在我的App开发中,它在设备上运行良好,但截至目前它还没有显示出来。但我确信代码正在运行。非常感谢帮助。

MacroEditViewController.h

@interface MacroEditViewController : UIViewController <UIAlertViewDelegate>

MacoEditViewController.m

- (IBAction)saveDatabase:(UIButton *)sender 
{
            [self alertStatusWithTitle:[NSString stringWithFormat:@"Are you sure you want to override %@ for %@? This cannot be undone (But you can Reset All Overrides on Macros screen).", macroMeal[1], macroMeal[0]] :@"Update Macros"];
}

- (void) alertStatus:(NSString *)msg :(NSString *)title
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                        message:msg
                                                       delegate:self
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:@"Cancel", nil];
    [alertView show];
}

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

}

2 个答案:

答案 0 :(得分:0)

为什么你这样称呼你的功能

[self alertStatus:[@"Are you sure you want to override?"] :@"Update Macros"];

像这样称呼

[self alertStatus:@"Are you sure you want to override?" :@"Update Macros"];

没有方括号,可能是问题

答案 1 :(得分:-2)

创建一个CIAlert.h

void CIAlert(NSString* title, NSString* alert);
void CIError(NSString* error); 

和CIAlert.m

#import "CIAlert.h"

void CIAlert(NSString* title, NSString* alert) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:alert delegate:nil
                        cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}

void CIError(NSString* error) {
  CIAlert(@"Error", error);
}

导入类CIAlert.h并像这样调用它......

CIAlert(@"Title", @"Enter your message");
相关问题