我有一個應用程序,其行爲有點像照片庫。他們從相機膠捲中選擇一張圖像,並將圖像顯示在UIImageView中。我共有9個圖像視圖。現在,我試圖添加按下編輯按鈕的功能,並允許用戶刪除照片。我通過在每個圖像上放置一個隱藏的UIButton來實現這一點,並且當點擊該按鈕時,出現一個UIAlertView,詢問他們是否想要刪除該圖像。在UIAlertView中點擊「Yes」後,我希望特定的UIImageView停止顯示圖片,並將每個顯示的圖片向左移動1行,以便圖庫中沒有空白區域。iOS:在NSMutableArray中移動對象
這是對我來說很棘手的地方,我對Objective-C還很陌生,不知道該怎麼做。我知道我應該可能會打電話moveRowAtIndexPath
和toIndexPath
,但我不確定是否應該在viewDidLoad,viewWillAppear中執行此操作,還是應該爲此創建自己的方法?以下是我的工作的樣本,這可能會或可能不相關:
- (void)applicationDidEnterBackground:(UIApplication*)application {
NSLog(@"Image on didenterbackground: %@", imageView);
NSMutableArray* array = [NSMutableArray arrayWithObject:[NSData dataWithData:UIImagePNGRepresentation(imageView.image)]];
[array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView2.image)]];
[array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView3.image)]];
[array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView4.image)]];
[self.user setObject:array forKey:@"images"];
[user synchronize];
}
- (void)viewDidLoad
{
self.user = [NSUserDefaults standardUserDefaults];
NSLog(@"It is %@", self.user);
NSMutableArray* array = [[self.user objectForKey:@"images"]mutableCopy];
imageView.image = [[UIImage alloc] initWithData:[array objectAtIndex:0]];
imageView2.image = [[UIImage alloc] initWithData:[array objectAtIndex:1]];
imageView3.image = [[UIImage alloc] initWithData:[array objectAtIndex:2]];
imageView4.image = [[UIImage alloc] initWithData:[array objectAtIndex:3]];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:app];
backToGalleryButton.hidden = YES;
tapToDeleteLabel.hidden = YES;
deleteButton1.hidden = YES;
[super viewDidLoad];
}
任何幫助或此建議非常感謝,謝謝!
這些圖像視圖在表視圖中? – 2012-04-02 00:52:05
不,我不是,我應該有,但我太過分了。如果有必要,我會盡管。 – John 2012-04-02 01:06:09