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



我有UIAlertView在模拟器中按预期工作,在我的应用程序开发的早期,它在设备上工作得很好,但到目前为止它没有出现。然而,我确定代码正在运行。非常感谢你的帮助。

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

为什么这样调用函数

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

这样称呼

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

没有方括号,可能就是问题所在

创建一个CIAlert.h

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

#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");

最新更新