Ios 屏幕上有多个UIAlerts,有些是重复的。有办法吗?

Ios 屏幕上有多个UIAlerts,有些是重复的。有办法吗?,ios,objective-c,xcode,uialertview,Ios,Objective C,Xcode,Uialertview,嘿,我有一个迭代数组并为每个项目显示UIAlert的方法。代码: NSLog(@"Number of unlocked stickers is: %lu",(unsigned long)[unlockedStickers count]); for(Sticker *unlockedSticker in unlockedStickers){ [self.stickerDictionary setObject:unlockedSticker forKey:u

嘿,我有一个迭代数组并为每个项目显示UIAlert的方法。代码:

NSLog(@"Number of unlocked stickers is: %lu",(unsigned long)[unlockedStickers count]);
        for(Sticker *unlockedSticker in unlockedStickers){

            [self.stickerDictionary setObject:unlockedSticker forKey:unlockedSticker.title];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unlocked Sticker" message:[NSString stringWithFormat:@"You unlocked the %@ sticker!",unlockedSticker.title] delegate:nil cancelButtonTitle:@"Ok!" otherButtonTitles:nil, nil];
            [alert show];



        }

我测试了一个包含4个贴纸对象的阵列。UIAlertView正在显示,但有4个以上的视图,有些视图正在重复。不知道为什么会这样。有人知道这是因为什么原因吗,还是因为bug同时显示了多个字符串?

我用4个字符串的数组测试了您的代码。我只收到4个警报

NSArray *testArray = @[@"0", @"1", @"2", @"3"];
for (NSString *item in testArray) {
    [[[UIAlertView alloc] initWithTitle:@"Alert" message:item delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil] show];
}

将日志设置为“计数”,并确保您确实拥有您认为拥有的数量。

然后后退一步。把我的密码放进去。看看它是否有效。如果是,请用testArray替换阵列。如果有效,则替换其他小部件。如果没有,找出它,然后替换下一部分。。。等等,直到我所有的零件都换成你的零件,它才能工作。