从今天早上开始我就有点困了。。。我正试图加载一个又一个图像,但是。。。它不起作用。。。我甚至没有显示我的第一张照片。。。
这是我的代码:
- (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];
}
不要介意我的代码的目标:)我只想显示uiimage,然后在显示第一个图像后调用checkResources方法时,我将发送给startImage另一个图像。
代码中可能存在的两个主要问题。。没有其他问题了。
1) 由于连续的addSubview方法,您的UI不会更新。。
2) 您的UIImage为null。。
检查1)
更改
[self checkResources];
至
[self performselector:@selector(checkResources) withObject:nil afterDelay:3] // this will give time for UI to update itself..
对以上代码使用"自动完成"。。。可能是拼写错误。。
检查2)
简称NSlog imageview.image
。。这将判断图像视图图像是否为空。。
如果这是你的真实代码,那么你就有一个无限循环。一个方法调用另一个。。否则:问题出在哪里?