How I can display an alert when I Received memory warning. Level=2 in iphone sdk

守給你的承諾、 提交于 2020-01-10 05:59:21

问题


In my application the user can add any number of images to the view. If he tries to add more images of bigger in memory size the application receives memory warning . So I want to display an alert to don't add images after receiving memory warning level = 2. Is it possible If so please help me. Thank You


回答1:


For User Experience sake, don't display an alert. Handling memory is your responsibility and not that of your user.




回答2:


What kind of alert do you want to dislplay? you could make an NSAlert like so:

[NSAlert alertWithError:@""];

EDIT

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [NSAlert alertWithError:@"You cannot make any more pictures"];
    canTakePicture = NO;
}

Create an instance variable called canTakePicture of type BOOL. When making a picture you should check if "canTakePicture" is YES or NO.




回答3:


In the didReceiveMemoryWarning write alertView.

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.}



回答4:


Your view controller method didReceiveMemoryWarning is called when application runs out of memory. Here you can create a alertview and display the appropriate message.

In general handle the warning here.



来源:https://stackoverflow.com/questions/6425043/how-i-can-display-an-alert-when-i-received-memory-warning-level-2-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!