Make sure your decksGallery viewWithTag:selectedEditDeck-1 is not returning nil and the image was actually deleted from your db before the refresh code running.
Up vote 1 down vote favorite share g+ share fb share tw.
I kno there has been many questions asked similar to this already. Please don't down vote or close the question. I have just tried implementing the solutions given for those questions.
Nothing worked for me. And my case is slightly different too. Here it goes, My app consists of a image gallery.
It is a scroll view which displays pics retrieved from the sqlite db. User can scroll the images , add or delete images etc. I can add a picture to the gallery dynamically. But the problem comes when I need to implement the delete functionality.
I use the following code but even after calling removeFromSuperView the image is not getting removed from the scrollview. Please help me out of this. It is very urgent I should complete this app ASAP.
Thanks in advance. -(void)deleteDeck{ if(selectedEditDeck! =0){ deck deleteSelectedDeck:selectedEditDeck; //deleting from database //problem starts here *** (UIImageView*)decksGallery viewWithTag:selectedEditDeck-1removeFromSuperview; self loadGallery; selectedEditDeck=0; //Ends here***** tableData release; tableData=NSMutableArray array; self showCardNamesinTable; aTableView reloadData; } } I have already created the uiscrollview in the loadview method.
Then to refresh the view after every deletion and addition of images so that I can display the updated gallery, I use the following piece of code: -(void)loadGallery{ //Reloading all for adding a single deck image. //Database part**** NSString *sqlStr = NSString stringWithFormat:@"select first_card from decksTable"; char *sql = (char*)sqlStr UTF8String; kidsFlashCardAppDelegate *appDelegate = UIApplication sharedApplication delegate; NSMutableArray *galleryImagesArray=appDelegate. DbConnection fetchColumnFromTable:sql col:0; NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); NSString *docDirectory = sysPaths objectAtIndex:0; numberofImages = galleryImagesArray count; printf("number is %d",numberofImages);//Database part of code ends here //In the following fragment of code I add images to UIscrollView for (int I = 0; I Tag=galleryImagesArray count; galleryImage.
Tag=i; printf("THE TAG IS %d",galleryImage. Tag); galleryImage. ClipsToBounds=YES; galleryImage.layer.
CornerRadius=11.0; galleryImage. BackgroundColor=UIColor clearColor; galleryImage. Image =UIImage imageWithContentsOfFile:filePath; decksGallery addSubview:galleryImage; galleryImage release; } decksGallery.
ContentSize = CGSizeMake(115*galleryImagesArray count, 80); //decksGallery reloadInputViews; } iphone ios uiscrollview uiimageview link|improve this question asked Aug 22 '11 at 8:55booleanBoy1,06728 100% accept rate.
Sorry for the way of formatting of code... n btw I use the tag of the imageview to refer to them while deletion... – booleanBoy Aug 22 '11 at 8:58 Can you put a break point and verify that your selectedDeck is being set and that code for deleting the deck from database is getting executed. After deleting check if fresh load from the database is again giving the same image. – Ved Aug 22 '11 at 9:24 no I store the image path in db and retrieve it.....actually the image gets removed when I remove it sequentially..say I have five images...when I start deleting from image with tag 5...it s getting deleted....but when I do it randomly it s not getting removed..n one more thing when I select the image wid tag zero..tat s the first img..all the images are gettn removed... – booleanBoy Aug 22 '11 at 9:46.
Make sure your decksGallery viewWithTag:selectedEditDeck-1 is not returning nil and the image was actually deleted from your db before the refresh code running. In addition, you are setting imageView. Tag = i; in your creation code, since the I would be 0 which is the tag's default value for every UIView, you'd better fix your creation code as well.
No it s not returning nil. And regarding what you have said about tag;s default value,could you please explain more on that? – booleanBoy Aug 22 '11 at 10:33 You'd better set .
Tag like this: imageView. Tag = kImageViewStartAt + i; , which kImageViewStartAt is #defined as a large number, 1000 for example. And you can get the imageView by using *** viewWithTag:kImageViewStartAt + selectedDeck - 1; – xuzhe Aug 22 '11 at 11:06 About your question itself, I think maybe you should check if the imageView you got with tag is the view you want to remove.
Also you'd better check about how many imageViews your decksGallery have by using NSLog("SubView Count: %@", decksGallery subViews count); and see if the count is correct. – xuzhe Aug 22 '11 at 11:12 Thanks a lot....I checked wid this..NSLog("SubView Count: %@", decksGallery subViews count); there were more number of subView than I expected. I have been calling the for loop again n again wid out removing subviews...Thanks a lot once again for your tip...It worked like a charm :D :) – booleanBoy Aug 22 '11 at 11:52 You are welcome.
:) – xuzhe Aug 22 '11 at 12:00.
If you just want to remove the image from your imageView, you can also do imageView. Image = nil; UIImageView*imageView = (UIImageView*)decksGallery viewWithTag:selectedEditDeck-1; imageView removeFromSuperview; imageView = nil.
Thanks for your answer...but still it s not working... – booleanBoy Aug 22 '11 at 9:50 can you check what is in the imageView object when your breakpoint hit the imageView removeFromSuperview; line... – Robin Aug 22 '11 at 9:51.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.