Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2010, 08:19 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 105
vamsi.ac is on a distinguished road
Default help with removeFromSuperView condition

i want to remove subview corresponding to that function.

if function1 is called

add pin1

if function2 is called

add pin2

if function1 is called again

remove existing pin1 and add new pin1 //this is what i want

but it is removing both pin1 and pin2 and adding new pin1 ...


so this is exactly what i don't want.


Code:
-(void)addressLocWithVar1:(CGFloat ) x andVar2:(CGFloat )y {

     [[self tabBarController] setSelectedIndex:2];

     UIImageView *addPin=[UIImageView alloc];

     //remove if there are already pins on the view

     for (UIImageView *addPin in [imageView subviews]){

     [addPin removeFromSuperview];
                    //i am asking addPin object to remove from superview, but bot pin1 and addPin objects are getting removed.
     }

     

     //setting up the animation propertis for the pin

     [UIView beginAnimations:nil context:nil];

     [UIView setAnimationDelegate:self];

     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

     [UIView setAnimationDuration:0.5];

     //creatingt the rect holding pin

     CGRect pinRect = CGRectMake(x , y-100, 16, 34);

     addPin = [[UIImageView alloc] initWithFrame:pinRect];

     [addPin setImage:[UIImage imageNamed:@"redpin.png"]];

     addPin.frame = CGRectMake(x, y, 16, 34 );

     [scrollView scrollRectToVisible:CGRectMake(x-160 , y-183, 320, 367) animated:YES];

     [imageView addSubview:addPin];

     [UIView commitAnimations];

     [addPin release];

}
Code:
-(IBAction)Loc: (id) sender{

     UIImageView *pin1=[UIImageView alloc];


     

     //remove if there are already pins on the view

     for (UIImageView *pin1 in [imageView subviews]) {

          [pin1 removeFromSuperview];

     }

     //setting up the animation propertis for the pin

     [UIView beginAnimations:nil context:nil];

     [UIView setAnimationDelegate:self];

     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

     [UIView setAnimationDuration:0.5];

     //creating the rect holding pin

     CGRect pinRect = CGRectMake(appDel.X4 , appDel.Y4-100, 16, 34);

     pin1 = [[UIImageView alloc] initWithFrame:pinRect];

     [pin1 setImage:[UIImage imageNamed:@"darkpin.png"]];

     pin1.frame = CGRectMake(appDel.X4, appDel.Y4, 16, 34 );

     [scrollView scrollRectToVisible:CGRectMake(appDel.X4-160 , appDel.Y4-183, 320, 367) animated:YES];

     [imageView addSubview:pin1];

     [UIView commitAnimations];

     [pin1 release];

}
vamsi.ac is offline   Reply With Quote
Old 09-09-2010, 09:49 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

How about just holding a reference to each pin, then just call it on the instance variable.

so

[self.pin1 removeFromSuperview];
self.pin1 = nil;
[self.pin2 removeFromSuperview];
self.pin2 = nil;

if either pin is nil, then calling removeFromSuperview is just basically ignored, no errors.

When you add a pin subview make sure you assign the corresponding instance variable.

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Old 09-09-2010, 10:01 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 105
vamsi.ac is on a distinguished road
Default

self.pin is not even structure or union error.

any other ideas?
vamsi.ac is offline   Reply With Quote
Old 09-10-2010, 09:03 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 105
vamsi.ac is on a distinguished road
Default

i am using

Code:
for (addPin in [imageView subviews]){
		[addPin removeFromSuperview];
		
	}
but it is removing the other subviews which are on the superview

is there any method to remove only addPin image from its superview?
vamsi.ac is offline   Reply With Quote
Old 09-14-2010, 07:23 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 62
devanshree.c is on a distinguished road
Default

Quote:
Originally Posted by vamsi.ac View Post
self.pin is not even structure or union error.

any other ideas?
try to tag those pin1 and pin2....
so call the required tagged pin when required as:
pin1.tag=1;
pin2.tag=2;


if(pin1.tag==1)
//do the neccessary
else
//blah blah blah
devanshree.c is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 337
10 members and 327 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, jenniead38, linkmx, nadav@webtview.com, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:51 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0