Ios 无法模拟调用ApplicationIDReceiveMemoryWarning:?
以下是呼叫代码:Ios 无法模拟调用ApplicationIDReceiveMemoryWarning:?,ios,nsnotificationcenter,Ios,Nsnotificationcenter,以下是呼叫代码: [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object:[UIApplication sharedApplication]]; 它无法从UIApplicationDelegate调用Applicatio
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
object:[UIApplication sharedApplication]];
它无法从UIApplicationDelegate
调用ApplicationIDReceiveMemoryWarning:
有什么问题吗?应该使用
UIApplicationMemoryWarningNotification
而不是UIApplicationIDReceiveMemoryWarningNotification
:
[[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationMemoryWarningNotification"
object:[UIApplication sharedApplication]];
在模拟器中,使用菜单触发低内存警告
您不能通过发布通知来模拟内存警告。
UIApplicationIDReceiveMemoryWarningNotification
在收到内存警告时由UIApplication
发布,但它没有观察到警告,因此在手动发布此类通知时不会调用视图控制器的didReceiveMemoryWarning:
方法
正如Rob已经指出的,您可以使用“simulate memory warning”(模拟内存警告)菜单项在iOS模拟器中模拟内存警告
您也可以在视图控制器中观察通知,而不是实现
didReceiveMemoryWarning:
,但我不建议这样做,因为当您以这种方式伪造内存警告时,系统提供的视图控制器的行为可能会有所不同。是否未调用该委托方法?我已经看到许多示例将通知名称设置为字符串,例如@“UIApplicationIDReceiveMemoryWarningNotification”。我怀疑这是真的,因为常数可能是同一个东西,即使改成NSString,它也不能工作。