user1256827
user1256827

Reputation: 63

cannot display UIImage one after one

I'm kind of stuck since this morning... i'm trying to load an image after another image but... it doesnt work... i don't even have my first image displayed ...

There is my code :

- (void) checkResources
{

    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSFileManager *manager = [NSFileManager defaultManager];
    NSDirectoryEnumerator *direnum = [manager enumeratorAtPath:bundleRoot];


    NSString *cuttedName;
    NSString *cuttedName1;



  for (NSString *path in direnum)
    {

        if ([[path pathExtension] isEqualToString:@"mp4"])
        {
            cuttedName1 = [path stringByReplacingOccurrencesOfString:@"ressources/" withString:@""];
            cuttedName = [cuttedName1 stringByReplacingOccurrencesOfString:@".mp4" withString:@""];
            if ([cuttedName isEqualToString:[NSString stringWithFormat:@"%d", num]]) 
            {
                NSString *media = [NSString stringWithFormat:@"%@/%@", bundleRoot, path];
                [self startSlideShow:media];
            }
        }
        else if ([[path pathExtension] isEqualToString:@"mov"])
        {
            cuttedName1 = [path stringByReplacingOccurrencesOfString:@"ressources/" withString:@""];
            cuttedName = [cuttedName1 stringByReplacingOccurrencesOfString:@".mov" withString:@""];
            if ([cuttedName isEqualToString:[NSString stringWithFormat:@"%d", num]]) 
            {
                NSString *media = [NSString stringWithFormat:@"%@/%@", bundleRoot, path];
                [self startSlideShow:media];
            }
        }
        else  if ([[path pathExtension] isEqualToString:@"png"])
        {
            cuttedName1 = [path stringByReplacingOccurrencesOfString:@"ressources/" withString:@""];
            cuttedName = [cuttedName1 stringByReplacingOccurrencesOfString:@".png" withString:@""];
            if ([cuttedName isEqualToString:[NSString stringWithFormat:@"%d", num]]) 
            {
                NSString *media = [NSString stringWithFormat:@"%@/%@", bundleRoot, path];
                num++;
            [self startImage:media];
            }
        }
    }

}
- (void) startImage:(NSString *)nameFile
{
    CGRect myImageRect = CGRectMake(0, 0, 200, 500);

    UIImageView *imageView;
    imageView = [[UIImageView alloc] initWithFrame:myImageRect];
    [imageView setImage:[UIImage imageNamed:@"0.png"]];
    NSLog(@"IAMGE %@", imageView.image);
    [self.view addSubview:imageView];
    [self performSelector:@selector(checkResources) withObject:nil afterDelay:10]; // this will give time for UI to update itself.. 
    [imageView release];

    }

- (void) startSlideShow:(NSString *)nameFile
{    
    NSURL *url = [NSURL fileURLWithPath:nameFile];//[[NSBundle mainBundle] pathForResource:@"2" ofType:@"mov"]];




    MPMoviePlayerController *moviePlayer = 
    [[MPMoviePlayerController alloc] initWithContentURL:url];
   // NSLog(@" URL : %@", url);

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];
    moviePlayer.view.frame = CGRectMake(0, 0, 500, 600);

    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];
   }



-(void)moviePlayBackDidFinish: (NSNotification*)notification
{ 
    MPMoviePlayerController *moviePlayer = [notification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self      
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayer];

    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
    {
       // [moviePlayer.view removeFromSuperview];
    }


    //[[moviePlayer release] addAnimation:animation forKey:kCATransition];


    num++;
    [self checkResources];
}

Don't mind about the goal of my code :) i just want to display the uiimage, then when the method checkResources is called after displayed the first image i will send to startImage another image.

Upvotes: 0

Views: 229

Answers (2)

Shubhank
Shubhank

Reputation: 21805

two main problem that can be in your code.. no other problem can be.

1) Your UI doesn't update because of continuous addSubview methods..

2) Your UIImage is null..

To check 1)

change

[self checkResources];

to

[self performselector:@selector(checkResources) withObject:nil afterDelay:3] // this will give time for UI to update itself.. 

use Auto Complete for the above code...might be spelling mistakes..

To check 2)

simply NSlog imageview.image .. this will tell if image view image is null or not..

Upvotes: 1

calimarkus
calimarkus

Reputation: 9977

If this is your real code you have a infinite loop. One method calls the other.. otherwise: Where is the problem?

Upvotes: 1

Related Questions