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];
}