I've been working on an error in my program but I cannot seem to find a solution.
我一直在研究程序中的一个错误,但似乎找不到解决方案。
When the user opens the camera the UIImagePickerController is displayed and works great. Although when he presses the home button on the iPhone I want to remove an object from an NSMutableArray.
当用户打开相机时,UIImagePickerController就会显示出来,效果很好。虽然当他按下iPhone上的home键时,我想从NSMutableArray中删除一个对象。
For instance: The user opens the camera. An object is added to an NSMutableArray in another class. The user presses the home button The object should be removed.
例如:用户打开相机。对象被添加到另一个类的NSMutableArray中。用户按下home键,对象应该被删除。
I can't call the remove method when the application moves to the background because I need the other object to remain in the array for background location services.
当应用程序移动到后台时,我不能调用remove方法,因为我需要将另一个对象保留在后台位置服务的数组中。
Is there a way to catch the event when either pressing the home button or when the UIImagePicker closes itself by the home button event?
当按下home按钮或UIImagePicker被home按钮事件关闭时,是否有办法捕捉事件?
2 个解决方案
#1
2
You will have to post notication. For that in appDelegate method:
你必须张贴通知。对于appDelegate方法中的那个:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"objectRemover" object:nil];
}
Now were you open UIImagePickerController in your view controller and its viewDidLoad method
现在你在你的视图控制器和它的viewDidLoad方法中打开UIImagePickerController
-(void)viewDidLoad
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(removeObject) name:@"objectRemover" object:nil];
}
add selector method in your view controller were you will remove your object as it will be called when home button is pressed.
在你的视图控制器中添加选择器方法你将移除你的对象,当按下home按钮时它将被调用。
-(void)objectRemover
{
// Your code remove object from array
}
#2
0
In ...AppDelegate.m class you will find following methods usefull
在……AppDelegate。你会发现以下方法是有用的
- (void)applicationWillResignActive:(UIApplication *)application {
- (void)applicationDidEnterBackground:(UIApplication *)application {
- (void)applicationWillTerminate:(UIApplication *)application {
#1
2
You will have to post notication. For that in appDelegate method:
你必须张贴通知。对于appDelegate方法中的那个:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"objectRemover" object:nil];
}
Now were you open UIImagePickerController in your view controller and its viewDidLoad method
现在你在你的视图控制器和它的viewDidLoad方法中打开UIImagePickerController
-(void)viewDidLoad
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(removeObject) name:@"objectRemover" object:nil];
}
add selector method in your view controller were you will remove your object as it will be called when home button is pressed.
在你的视图控制器中添加选择器方法你将移除你的对象,当按下home按钮时它将被调用。
-(void)objectRemover
{
// Your code remove object from array
}
#2
0
In ...AppDelegate.m class you will find following methods usefull
在……AppDelegate。你会发现以下方法是有用的
- (void)applicationWillResignActive:(UIApplication *)application {
- (void)applicationDidEnterBackground:(UIApplication *)application {
- (void)applicationWillTerminate:(UIApplication *)application {