プロジェクトにViewControllerがあり、2つの画像をクリックして、同じ画面に拡大縮小して表示する必要があります。サーバーに両方の画像をアップロードした後、このプロセスを繰り返すことができます。写真を撮るために私はUIImagePickerControllerを使用しています。写真を8回クリックすると、レベル1と2のメモリ警告が表示されます。
StackOverflowで関連する質問を参照したとき、それらのほとんどはUIImagePickerControllerをシングルトンオブジェクトにすることを提案しました。そこで、UIImagePickerControllerのサブクラスである新しいシングルトンクラスを作成しました。メインのViewControllerで、このカスタムクラスのオブジェクトを作成し、それを繰り返し使用しています。しかし残念ながら、これも役に立ちません。画像を8回クリックしても、まだメモリ警告が表示されます。
いくつかのスニペットも投稿する-
UIImagePickerControllerのサブクラスの作成-
@interface ImagePickerControllerSingelton : UIImagePickerController <UIImagePickerControllerDelegate>
{
}
+(ImagePickerControllerSingelton *) sharedPicker;
シングルトンクラスの実装-
static ImagePickerControllerSingelton *sharedInstance = nil;
+(ImagePickerControllerSingelton*) sharedPicker
{
@synchronized (self){
if (sharedInstance == nil) {
[[self alloc] init];
return sharedInstance;
}
}
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [super allocWithZone:zone];
return sharedInstance; // assignment and return on first allocation
}
}
return nil; //on subsequent allocation attempts return nil
}
現在、メインのViewControllerクラスにあります-
ImagePickerControllerSingelton *imagePicker;
imagePicker = [ImagePickerControllerSingelton sharedPicker];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image?
imagePicker.allowsEditing = YES;
imagePicker.showsCameraControls = NO;
imagePicker.wantsFullScreenLayout = YES;
imagePicker.cameraOverlayView = [self createOverlayView];
[self presentModalViewController:imagePicker animated:YES];
私は何か間違ったことをしていますか?みんな助けてください!