0

I am working on an iPad application in Xcode 5 for a jigsaw puzzle game. I created the layout in storyboard, adding uiimageviews for each of 9 frames that would hold part of the image that was going to be the puzzle, and placed them on the view controller. Someone else has since removed the storyboard from the game and I need to go back and finish up the puzzle without it. The biggest issue I have is that the position of the frames seem to be being set somewhere outside of the view controller.h or .m classes and I can't find it. I am able to change the position of the pieces using image1.center in the touchesmoved method, but not in the viewdidload. I have been trying to track down where this is being set for several hours and am having no luck. Setting any movement of the center in viewdidload,viewwillappear, viewdidappear etc do not change the position as expected.

Can anyone either guide me on a way to change the image1.center after the view loads but without any user input, or else tell me how to trace all changes that are occurring in the view? I don't think seeing my code will help in this question since it is not seemingly changed in the classes that I am looking at, but I will post what works and what doesn't. I am only posting the portions that touch the uiimageview (1-9)

from .h

@implementation PuzzleViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

@interface PuzzleViewController : UIViewController
{
    UIImageView *image1;
    UIImageView *image2;
    UIImageView *image3;
    UIImageView *image4;
    UIImageView *image5;
    UIImageView *image6;
    UIImageView *image7;
    UIImageView *image8;
    UIImageView *image9;
    UIImage *puzzlePic;

}

from .m

- (void)viewDidLoad
{
    [super viewDidLoad];

    //set up buttons to accept user input
    image1.userInteractionEnabled = true;
    image2.userInteractionEnabled = true;
    image3.userInteractionEnabled = true;
    image4.userInteractionEnabled = true;
    image5.userInteractionEnabled = true;
    image6.userInteractionEnabled = true;
    image7.userInteractionEnabled = true;
    image8.userInteractionEnabled = true;
    image9.userInteractionEnabled = true;

    // Do any additional setup after loading the view from its nib.
    puzzlePic = [LLFileManager getImage:@"star7.gif" folder:@"animation_images"];

    [self placeImage];

}

// handle touches within images to move
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.view];
    if([touch view] == image1){
        image1.center = touchLocation;
    }
    else if([touch view] == image2){
        image2.center = touchLocation;

    }
    else if([touch view] == image3){
        image3.center = touchLocation;
    }
    else if([touch view] == image4){
        image4.center = touchLocation;
    }
    else if([touch view] == image5){
        image5.center = touchLocation;
    }
    else if([touch view] == image6){
        image6.center = touchLocation;
    }
    else if([touch view] == image7){
        image7.center = touchLocation;
    }
    else if([touch view] == image8){
        image8.center = touchLocation;
    }
    else if([touch view] == image9){
        image9.center = touchLocation;
    }
}

// splits image into 9 equal parts, takes input of a ui image

-(NSArray *)splitImage9:(UIImage *)im{
    NSMutableArray *images = [NSMutableArray array];
    CGSize imageSize = im.size;
    CGFloat xPos = 0.0, yPos = 0.0;
    CGFloat width = imageSize.width/3;
    CGFloat height = imageSize.height/3;
    for (int y = 0; y < 3; y++) {
        xPos = 0.0;
        for (int x = 0; x < 3; x++) {

            CGRect rect = CGRectMake(xPos, yPos, width, height);
            CGImageRef cImage = CGImageCreateWithImageInRect([im CGImage],  rect);

            UIImage *dImage = [[UIImage alloc] initWithCGImage:cImage];
            [images addObject:dImage];
            xPos += width;
        }
        yPos += height;
    }
    return images;
}

// position pieces on board load

-(void)positionPieces{ // test, not working
    CGPoint piece = CGPointMake(50,100);
    image2.center =  piece;

}


// places the cut images into view placeholders
-(void)placeImage{
    NSArray *puzzleImage = [self splitImage9: puzzlePic];
    [image1 setImage:[puzzleImage objectAtIndex:0]];
    [image2 setImage:[puzzleImage objectAtIndex:1]];
    [image3 setImage:[puzzleImage objectAtIndex:2]];
    [image4 setImage:[puzzleImage objectAtIndex:3]];
    [image5 setImage:[puzzleImage objectAtIndex:4]];
    [image6 setImage:[puzzleImage objectAtIndex:5]];
    [image7 setImage:[puzzleImage objectAtIndex:6]];
    [image8 setImage:[puzzleImage objectAtIndex:7]];
    [image9 setImage:[puzzleImage objectAtIndex:8]];
}
user1814946
  • 181
  • 2
  • 11
  • It isn't happening in the code you are showing (as you know). So either it is happening thru the loading of a nib or storyboard, or it is happening in code. Look for a storyboard, or a nib called _PuzzleViewController.xib_, or for any code referring to names like `image1`. – matt Apr 03 '14 at 04:13
  • I've done a search for image1 and don't find anything. There is no storyboard in the project. I'll check for a .xib but haven't seen one. I added the init method to my question, I believe it says there was no nib. I'm at a loss. – user1814946 Apr 03 '14 at 04:17
  • The words "puzzle" "image1...image2...etc" "storyboard" do not return anything in the entire project that I haven't listed here. – user1814946 Apr 03 '14 at 04:19
  • Do you know how to search for files by name/suffix? Use the search field at the _bottom_ of the project (file) navigator. Search for "storyboard" and also for "xib". – matt Apr 03 '14 at 04:22
  • Do you know how to do a _global_ search in your project? Use the search field at the _top_ of the search navigator (not at the top of the file editor). – matt Apr 03 '14 at 04:26
  • Used both search bars, no results. Is it possible the project retained information from the storyboard that was deleted, but it is now inaccessible? – user1814946 Apr 03 '14 at 04:30
  • Well, it may be that without the storyboard the project will not build. You may be able to build it only because you _used_ to be able to build it. Why was it deleted? I'm not persuaded that this is the issue, but it's interesting. :) – matt Apr 03 '14 at 04:34
  • There are two teams working on different aspects of this app and they decided it was time to merge. Some members decided the storyboards needed to be eliminated to make this work, so it was tossed. – user1814946 Apr 03 '14 at 04:36
  • Are you sure you _have_ all the code? At the moment, there isn't even code that creates these image views and adds them to the interface! At least, you have not shown me any. So I assure you that if no code creates the image views and adds them to the interface, and if there is no nib, then there are no image views and the screen is empty. – matt Apr 03 '14 at 04:37
  • Look for `addSubview:`. That's the only way (besides a nib) that anything ever gets into the interface! – matt Apr 03 '14 at 04:38
  • I think what's running in my simulator is a ghost of storyboard past. I was just thinking the same thing -- these aren't added to the view. I pushed the code to my iPad: blank screen. – user1814946 Apr 03 '14 at 04:38
  • There you go. And try cleaning the project as I explain here: http://stackoverflow.com/questions/5714372/how-to-empty-caches-and-clean-all-targets-xcode-4/6247073#6247073 I bet you a dollar that after you do that, it will be blank everywhere. – matt Apr 03 '14 at 04:40
  • In that case, whoever deleted the storyboard hosed the project. :) – matt Apr 03 '14 at 04:40
  • Of course if this is git you can just bring the storyboard back. :)))) – matt Apr 03 '14 at 04:41
  • Well that did it. As annoyed as I am about losing the past 5 hours of work to a storyboard ghost, I really appreciate you figuring it out. Now I can actually do some work. Thanks! Post as an answer and I will accept :) – user1814946 Apr 03 '14 at 04:51
  • So what was the actual outcome? The storyboard is gone and the project is hosed? - I guess now your job is to create the interface _in code_... – matt Apr 03 '14 at 04:53
  • Luckily this portion of the project was already completely done in code other than the uiimageview placeholders that were on the storyboard. Now that it's responding to my frame commands I haven't lost much. I'd be very unhappy if it had been all storyboard... – user1814946 Apr 03 '14 at 05:03

1 Answers1

1

The biggest issue I have is that the position of the frames seem to be being set somewhere outside of the view controller.h or .m classes and I can't find it.

If the storyboard is gone, and if no code has been added to put the image views into the interface, then the interface should be empty. The reason you are seeing the interface at all must be because you are accidentally running an outdated version of the project.

To solve that problem, clean the project as I explain here:

How to Empty Caches and Clean All Targets Xcode 4

You will then find, when you run the project again, that the interface is now empty and the mystery is solved: the frames have no position, because there are no frames, because there are no image views at all.

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141