我想在我自己的项目中添加多个图像,如7个图像,但在删除和添加图像是麻烦。我也成功添加图像。而且还会删除成功。但是当我添加了删除图像时,图像位置移动了错误的位置。任何人都可以帮我纠正我的代码。提前谢谢。
这是我的代码
NSInteger x=0,i=0,z=0;
NSInteger im=0,im1=0,im2=0,im3=0,im4=0,im5=0,im6=0;
-(IBAction) selectimg
{
if(i>6)
{
alertbox...
}
else {
popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Capture Image" otherButtonTitles:@"Gallery", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
}}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
if (i==0)
{
bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage];
[scrollview addSubview:bgImage];
myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton setTitle:@"Delete" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
[scrollview addSubview:myButton];
x=x+100;
}
if (i==1)
{
bgImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage1.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage1];
[scrollview addSubview:bgImage1];
myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton1.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton1 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton1 addTarget:self action:@selector(buttonClicked1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton1];
[scrollview addSubview:myButton1];
x=x+100;
}
if (i==2)
{
bgImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage2.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage2];
[scrollview addSubview:bgImage2];
myButton2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton2.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton2 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton2 addTarget:self action:@selector(buttonClicked2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton2];
[scrollview addSubview:myButton2];
x=x+100;
}
if (i==3)
{
bgImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage3.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage3];
[scrollview addSubview:bgImage3];
myButton3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton3.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton3 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton3 addTarget:self action:@selector(buttonClicked3) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton3];
[scrollview addSubview:myButton3];
x=x+100;
}
if (i==4)
{
bgImage4 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage4.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage4];
[scrollview addSubview:bgImage4];
myButton4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton4.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton4 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton4 addTarget:self action:@selector(buttonClicked4) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton4];
[scrollview addSubview:myButton4];
x=x+100;
}
if (i==5)
{
bgImage5 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage5.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage5];
[scrollview addSubview:bgImage5];
myButton5 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton5.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton5 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton5 addTarget:self action:@selector(buttonClicked5) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton5];
[scrollview addSubview:myButton5];
x=x+100;
}
if (i==6)
{
bgImage6 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage6.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage6];
[scrollview addSubview:bgImage6];
myButton6 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton6.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton6 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton6 addTarget:self action:@selector(buttonClicked6) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton6];
[scrollview addSubview:myButton6];
x=x+100;
}}
else if (buttonIndex == 1)
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
im1=0,im2=0,im3=0,im4=0,im5=0,im6=0;
if (i==0)
{
NSLog(@"in 0");
bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage];
[scrollview addSubview:bgImage];
myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton setTitle:@"Delete" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
[scrollview addSubview:myButton];
x=x+100;
}
if (i==1)
{
NSLog(@"in 1");
bgImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage1.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage1];
[scrollview addSubview:bgImage1];
myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton1.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton1 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton1 addTarget:self action:@selector(buttonClicked1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton1];
[scrollview addSubview:myButton1];
x=x+100;
}
if (i==2)
{
NSLog(@"in 2");
bgImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage2.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage2];
[scrollview addSubview:bgImage2];
myButton2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton2.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton2 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton2 addTarget:self action:@selector(buttonClicked2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton2];
[scrollview addSubview:myButton2];
x=x+100;
}
if (i==3)
{
bgImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage3.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage3];
[scrollview addSubview:bgImage3];
myButton3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton3.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton3 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton3 addTarget:self action:@selector(buttonClicked3) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton3];
[scrollview addSubview:myButton3];
x=x+100;
}
if (i==4)
{
NSLog(@"in 4");
bgImage4 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage4.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage4];
[scrollview addSubview:bgImage4];
myButton4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton4.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton4 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton4 addTarget:self action:@selector(buttonClicked4) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton4];
[scrollview addSubview:myButton4];
x=x+100;
}
if (i==5)
{
NSLog(@"in 5");
bgImage5 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage5.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage5];
[scrollview addSubview:bgImage5];
myButton5 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton5.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton5 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton5 addTarget:self action:@selector(buttonClicked5) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton5];
[scrollview addSubview:myButton5];
x=x+100;
}
if (i==6)
{
NSLog(@"in 6");
bgImage6 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage6.image = [UIImage imageNamed:@"default.jpg"];
[self.view addSubview:bgImage6];
[scrollview addSubview:bgImage6];
myButton6 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton6.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton6 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton6 addTarget:self action:@selector(buttonClicked6) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton6];
[scrollview addSubview:myButton6];
x=x+100;
}}}
- (void)imagePickerController:(UIImagePickerController *)UIPicker didFinishPickingImage:(UIImage *)info editingInfo:(NSDictionary *)dictionary
{
[UIPicker dismissModalViewControllerAnimated:NO];
if(i==0)
{
bgImage.image=info;
}
else if (i==1)
{
bgImage1.image=info;
}
else if (i==2)
{
bgImage2.image = info;
}
else if (i==3)
{
bgImage3.image = info;
}
else if(i==4)
{
bgImage4.image = info;
}
else if(i==5)
{
bgImage5.image = info;
}
else if(i==6)
{
bgImage6.image = info;
}
i++;
}
- (void)buttonClicked
{
if((im1==1)&&(im2==1)&&(im3==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage.frame;
myButton6.frame=myButton.frame;
}
else if((im1==1)&&(im2==1)&&(im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton.frame;
}
else if((im1==1)&&(im2==1)&&(im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton.frame;
}
else if((im1==1)&&(im2==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
bgImage3.frame=bgImage.frame;
myButton6.frame=myButton3.frame;
myButton3.frame=myButton.frame;
}
else if((im1==1)&&(im3==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im1==1)&&(im2==1)&&(im3==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton.frame;
}
else if((im1==1)&&(im2==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton.frame;
}
else if((im1==1)&&(im2==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton.frame;
}
else if((im1==1)&&(im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im1==1)&&(im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im1==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im2==1)&&(im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im2==1)&&(im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im2==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im3==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im1==1)&&(im2==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton.frame;
}
else if((im1==1)&&(im3==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im1==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im1==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if((im2==1)&&(im3==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im2==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im2==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if((im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if(im1==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton.frame;
}
else if(im2==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if(im3==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if(im4==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else if(im5==1)
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
else
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
bgImage1.frame=bgImage.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
myButton1.frame=myButton.frame;
}
[bgImage removeFromSuperview];
[bgImage release];
bgImage=nil;
[myButton removeFromSuperview];
myButton=nil;
i--;
x=x-100;
im=1;
}
- (void)buttonClicked1
{
if(im==1)
{
[self buttonClicked];
}
else
{
if((im2==1)&&(im3==1)&&(im4==1)&&(im5==1))
bgImage6.frame=bgImage1.frame;
myButton6.frame=myButton1.frame;
}
else if((im2==1)&&(im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton1.frame;
}
else if((im2==1)&&(im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage1.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton1.frame;
}
else if((im2==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
myButton6.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
}
else if((im3==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else if((im2==1)&&(im3==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton1.frame;
}
else if((im2==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
}
else if((im2==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
}
else if((im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else if((im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else if((im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else if(im2==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
}
else if(im3==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else if(im4==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else if(im5==1)
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
else
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
bgImage2.frame=bgImage1.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
myButton2.frame=myButton1.frame;
}
[bgImage1 removeFromSuperview];
[bgImage1 release];
bgImage1=nil;
[myButton1 removeFromSuperview];
myButton1=nil;
im1=1;
i--;
x=x-100;
}
}
- (void)buttonClicked2
{
if((im==1)&&(im1==1))
{
[self buttonClicked];
}
else if((im1==1)||(im==1))
{
[self buttonClicked1];
}
else
{
if((im3==1)&&(im4==1)&&(im5==1))
{
bgImage6.frame=bgImage2.frame;
myButton6.frame=myButton2.frame;
}
else if((im3==1)&&(im4==1))
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage2.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton2.frame;
}
else if((im3==1)&&(im5==1))
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton2.frame;
}
else if((im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
myButton6.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
}
else if(im3==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage2.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton1.frame;
}
else if(im4==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
}
else if(im5==1)
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton1.frame;
}
else
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
bgImage3.frame=bgImage2.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
myButton3.frame=myButton2.frame;
}
[bgImage2 removeFromSuperview];
[bgImage2 release];
bgImage2=nil;
[myButton2 removeFromSuperview];
myButton2=nil;
im2=1;
i--;
x=x-100;
}
}
- (void)buttonClicked3
{
NSLog(@"Delete 3");
if((im4==1)&&(im5==1))
{
bgImage6.frame=bgImage3.frame;
myButton6.frame=myButton3.frame;
}
else if(im4==1)
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage3.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton3.frame;
}
else if(im5==1)
{
bgImage6.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
myButton6.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
}
else
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
bgImage4.frame=bgImage3.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
myButton4.frame=myButton3.frame;
}
[bgImage3 removeFromSuperview];
[bgImage3 release];
bgImage3=nil;
[myButton3 removeFromSuperview];
myButton3=nil;
im3=1;
i--;
x=x-100;
}
- (void)buttonClicked4
{
if(im5==1)
{
bgImage6.frame=bgImage4.frame;
myButton6.frame=myButton4.frame;
}
else
{
bgImage6.frame=bgImage5.frame;
bgImage5.frame=bgImage4.frame;
myButton6.frame=myButton5.frame;
myButton5.frame=myButton4.frame;
}
[bgImage4 removeFromSuperview];
[bgImage4 release];
bgImage4=nil;
[myButton4 removeFromSuperview];
myButton4=nil;
im4=1;
i--;
}
我在上面粘贴的内容中找不到问题。我错过了什么吗?
答案 0 :(得分:0)
最好在下面使用NSMutableArray.Use
UITableView.Look
,这可能有用。添加,删除&插入。你必须看到我宣布的内容。
.h---
NSMutabeArray *list;
.m---
-(IBAction)AddButtonAction:(id)sender
{
[list addObject:@"SaturDay"];
[tableView reloadData];
}
-(IBAction)DeleteButtonAction:(id)sender
{
[list removeLastObject];
[tableView reloadData];
}
-(IBAction) Edit:(id)sender
{
if(self.editing)
{
[super setEditing:NO animated:NO];
[tableView setEditing:NO animated:NO];
[tableView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
[super setEditing:YES animated:YES];
[tableView setEditing:YES animated:YES];
[tableView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}