iPhone My程序在使用

iPhone My程序在使用,iphone,Iphone,我正在制作一个程序,从服务器加载视频,然后在本地保存。当我同步操作时,程序运行得很好。当我将其更改为异步执行时,当用户返回到预屏幕并尝试按下任何带有sig bad memory错误的按钮时,它将崩溃 视频加载和播放正常。当他们点击“完成”按钮时,该方法 - (void) moviePlayBackDidFinish:(NSNotification*)notification;{ [ mp stop]; // [ mp release]; [self dismissModalV

我正在制作一个程序,从服务器加载视频,然后在本地保存。当我同步操作时,程序运行得很好。当我将其更改为异步执行时,当用户返回到预屏幕并尝试按下任何带有sig bad memory错误的按钮时,它将崩溃

视频加载和播放正常。当他们点击“完成”按钮时,该方法

- (void) moviePlayBackDidFinish:(NSNotification*)notification;{
    [ mp stop]; 
//  [ mp release];
    [self dismissModalViewControllerAnimated: true];
}
退出并进入预屏幕。现在在预屏幕上,如果他们点击任何按钮,我会得到一个

我做了以下几件事 1.文件很大,所以我修改了我的 [[NSMutableData alloc]initWithLebLength:0];至[[NSMutableData alloc]初始容量:200000];,不起作用

- (void)viewDidLoad {   

    [super viewDidLoad];

    // construct the url
    NSString *mServerName=[ [ NSString alloc] initWithString:@"http://www.besttechsolutions.biz/projects/golfflix/" ];
    NSString *mFullName=[ mServerName stringByAppendingString: mVedioName  ]; 
    NSURL *movieUrl=[[NSURL alloc] initWithString:mFullName];

    // start the transmision
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:movieUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
    receivedData = [[NSMutableData alloc] initWithCapacity:100000000];
    connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];

    [movieUrl release];
    [mServerName release];

}
///////////////////////////////////////////////////////////////////////////////////////////////
// background loading
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [receivedData setLength:0];
}

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [receivedData appendData:data];
}

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [connection release];
}

- (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
    return nil;
}



- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [connection release];


    /////////////////////////////////////////////////////////////////////////////////
    // Save vedio
    NSFileManager *mFile= [NSFileManager defaultManager];
    NSString *filename=[ NSHomeDirectory() stringByAppendingPathComponent:mVedioName];
    [mFile createFileAtPath:filename contents: receivedData attributes:nil];
    [ receivedData release  ];

    // play it
    NSURL *fileUrl=[ NSURL fileURLWithPath:filename];
    if (mp==nil)
    {
        mp=[[MPMoviePlayerController alloc] initWithContentURL: fileUrl];
        [mp.view setFrame: self.view.bounds];
        [self.view addSubview: mp.view];

        // Set movie player layout
        [mp setControlStyle:MPMovieControlStyleFullscreen];
        [mp setFullscreen:YES];

        // May help to reduce latency
        [mp prepareToPlay];

        [mp play];
    }
    else {
        [mp stop];
        mp.contentURL=fileUrl;  
        [mp play];  
    }

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];
    // movie reced save to file
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification;{
    [ mp stop]; 
//  [ mp release];
    [self dismissModalViewControllerAnimated: true];
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
任何关于这方面的想法都会很好,本坚持了好几天!!!!
Ted

如果要返回预屏幕,请尝试将代码切换到

    -(void)viewWillAppear:(BOOl)animated
     {
         //code 
     }
因为在加载视图时,函数viewDidLoad只调用一次。
但是只要视图出现,就会调用函数viewwillbeen。

谢谢,我以前从未听说过这种方法,总是学习新东西:)