在解除moviePlayerController之后,UITableView不记得它的滚动位置

时间:2013-07-26 05:49:15

标签: iphone ios objective-c uitableview

我有UITableView个自定义单元格,在此表中,视频列表显示10到10来自服务器使用分页概念。当你点击视频列表然后视频开始在moviePlayerController中播放,但是当你点击moviePlayerController的完成Button时,你的视频列表就会被刷新。 我想停止这种更新,并希望看到UITableView与播放视频之前相同。

请参阅代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    CurrentVideoIndex =indexPath;
    NSDictionary *VideoUrlDic = [videoList objectAtIndex:indexPath.row];
    NSString *VideoUrl = [VideoUrlDic objectForKey:@"playUrl"];
    //NSLog(@"VideoUrl is ::%@",VideoUrl);

    NSURL *fileURL = [NSURL URLWithString:VideoUrl];

    moviePlayerController= [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];

    [[moviePlayerController moviePlayer] prepareToPlay];
    //[[moviePlayerController moviePlayer] setUseApplicationAudioSession:NO];
    [[moviePlayerController moviePlayer] setShouldAutoplay:YES];
    //[[moviePlayerController moviePlayer] setControlStyle:2];
    //[[moviePlayerController moviePlayer] setRepeatMode:MPMovieRepeatModeOne];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [self presentMoviePlayerViewControllerAnimated:moviePlayerController];
}
-(void)videoPlayBackDidFinish:(NSNotification*)notification  {

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

    [moviePlayerController.moviePlayer stop];
    moviePlayerController = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:moviePlayerController  name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];

    if (![[self modalViewController] isBeingDismissed])
    {
        [self dismissMoviePlayerViewControllerAnimated];
        [moviePlayerController.view removeFromSuperview];
        [self hideProgress];
    }

//     [self.tableView scrollToRowAtIndexPath:CurrentVideoIndex atScrollPosition:UITableViewScrollPositionTop  animated:NO];
    //loading=NO;
}

#pragma UIScroll View Method::

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
        if (!loading) {
            float endScrolling = scrollView.contentOffset.y + scrollView.frame.size.height;
            if (endScrolling >= scrollView.contentSize.height)
            {
                [self performSelector:@selector(loadDataDelayed) withObject:nil afterDelay:2];

            }
        }
    }

    #pragma UserDefined Method:::
    -(void)loadDataDelayed{

        counter +=10;
        NSString *count = [NSString stringWithFormat:@"%d",counter];
        NSLog(@"count value after Scrolling  is :::%@",count);
        [self createConnection:count];
    }

1 个答案:

答案 0 :(得分:0)

当打开视频播放器时,打开presentmodalviewcontroller,当你按下完成按钮时,它会关闭modalviewcontroller,因为你初始化的任何东西都将被释放,并且再次调用整个视图,所以为了避免写入代码viewwillappear方法。

当您再次按下完成按钮时会创建表视图,这是解除任何控制器时唯一的解决方案。在viewwillappear方法中使用

  

的NSLog(@ “”);

声明你会知道我想说的是什么