我今天早上被卡住了...我試圖加載一個圖像後,另一個圖像,但...它不工作...我甚至沒有我的第一個圖像顯示...不能顯示UIImage一個接一個
有我的代碼:
- (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我會發送第一張圖片來開始圖片另一張圖片。
好吧,我做了,但我仍然有問題。我試圖解釋我在做什麼: checkRessources調用首先我的方法「startImage:(NSString *)nameFile」 然後,當startImage完成時,我做了你所做的然後checkRessources被調用,但現在checkRessource將加載另一種顯示視頻的方法。 問題是:顯示的視頻先不顯示圖像...它就像視頻沒有給足夠的時間來顯示圖像 – user1256827 2012-03-08 16:19:48
如果我不加載播放視頻的方法圖像是好的加載和顯示 – user1256827 2012-03-08 16:25:28
將延遲更改爲更大的值..並再試一次..其他明智地發佈您的整個代碼..這兩個函數 – Shubhank 2012-03-08 16:28:32