我是iOS新手.我正在开发一个包含notification的应用程序.当通知到达时使用应用程序显示alertView.一切正常但如果通知到达时另一个alertView已经显示问题则启动.Notification alertView显示在上面现有alertView.当我点击确定通知alertView UI导航到新的视图控制器,然后第一个alertView仍然显示.如果我点击该alertView我的应用程序崩溃.
当我点击通知alertView时,有没有办法关闭显示的所有警报视图.
我有这个解决方案
for (UIWindow* window in [UIApplication sharedApplication].windows)
{
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
if ([[subviews objec`enter code here`tAtIndex:0] isKindOfClass:[UIAlertView class]])
[(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
但是此代码适用于iOS6而非iOS7.我想在iOS7中使用相应的代码.
谁能请帮忙.谢谢
我正在解析一个json数据,如果它有一个内容,那么该字段之一就是一个数组.但是如果它没有内容,那么它只是一个字符串"No result".我使用以下代码来解析它:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
//URL is called.
if ([status isEqualToString:@"success"])
{
if ([[[json objectForKey:@"Items"] objectForKey:@"item_list"] isKindOfClass:[NSString class]])
{
_Label.text = [NSString stringWithFormat:@"0"];
ItemsArray = [[NSMutableArray alloc]init];
}
else
{
ItemsArray = [[json objectForKey:@"Items"] objectForKey:@"item_list"];
NSLog(@"%d",[ItemsArray count]);
float Amount = 0;
NSLog(@"%d",[ItemsArray count]);
if ([ItemsArray count]>0)
{
for (int i=0; i<[ItemsArray count]; i++)
{
NSMutableDictionary * temp3 = [ItemsArray objectAtIndex: i];
NSString * x = [temp3 objectForKey:@"final"];
Amount = Amount + [x floatValue];
}
Label.text = [NSString stringWithFormat:@"%.2f",BidAmount];
} …Run Code Online (Sandbox Code Playgroud)