UIAlertController ให้ข้อความแสดงข้อผิดพลาดของคอนโซล

ฉันมีรหัสต่อไปนี้เพื่อแสดงข้อความแสดงข้อผิดพลาดใน UIAlertController ใน IOS 13 มันทำงานได้อย่างสมบูรณ์แบบใน IOS 11 แต่ตอนนี้ฉันได้รับข้อผิดพลาดของคอนโซลดังต่อไปนี้ ใครช่วยกรุณาแนะนำวิธีการนี้สามารถแก้ไขได้ขอบคุณ

-(void)errorMessage
    {

    UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Information",information)
                                                                   message:displaymessage
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK",ok)
                                                            style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {}];

    [alert addAction:defaultAction];

    [self presentViewController:alert animated:YES completion:nil];


}

ข้อผิดพลาด:

> 2020-04-18 00:19:07.958139+0100 TrigCalculator[9298:636378] Warning:
> Attempt to present <UIAlertController: 0x7fa448043200>  on
> <UITabBarController: 0x7fa44b008200> which is already presenting
> <UIAlertController: 0x7fa44787fc00>

person superllanboy    schedule 17.04.2020    source แหล่งที่มา


คำตอบ (1)


หลังจากตรวจสอบปัญหานี้เพิ่มเติม ฉันพบว่าตรรกะของฉันในที่อื่นอาจทำให้ข้อความแจ้งเตือนสองข้อความต้องการแสดงพร้อมกัน ฉันไม่ต้องการปรับโครงสร้างตรรกะของฉันใหม่ ดังนั้นจึงพบว่าการแก้ไขโค้ดของฉันต่อไปนี้ได้ผล Xcode เวอร์ชันก่อนหน้าไม่ได้บ่นเกี่ยวกับเรื่องนี้ แต่เวอร์ชันล่าสุดหยิบยกปัญหาและออกคำเตือน

if (self.presentedViewController != nil)
{[self.presentingViewController dismissViewControllerAnimated:true completion:nil];}
else
{
[self presentViewController:alert animated:YES completion:nil];
}

โปรดแสดงความคิดเห็นหากคุณรู้สึกว่านี่เป็นแนวทางที่ผิด

ขอบคุณ

person superllanboy    schedule 18.04.2020