1

デバイスの向きが変わったときの私のuitableview呼び出しreloaddata(表示されるセルの数が変更されるため、ドキュメントから理解できる限りレイアウト サブビューで呼び出されるため、理にかなっています)、ダウンロードを実行しているため、これは私にとって問題です。一部のファイルが突然表示されないようにします。デフォルトの動作を停止して、必要なときに手動でリロードできるようにする方法はありますか?

編集:私はよりよく説明しようとします。テーブルビューの上部に、サーバーからの同期要求を開始する「同期」というボタンがあります。この同期要求はまず、テーブルビューに表示したい情報を保持する JSON オブジェクトを取得しますが、それぞれuitableviewitems は、インターネットからダウンロードしているファイルを表します。

ファイルのダウンロード中は画面にアクティビティ インジケーターが表示されますが、ファイルのダウンロードが終了したときにのみ、テーブルをリロードします。問題は、ユーザーが向きを変えると がUITableview自動的に呼び出さreloaddataれるため、ダウンロードしたファイルのダウンロードが完了する前にセルが json からの情報でいっぱいになることです。

コード:

@implementation BIDManageFilesViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newDataFinishedDownloading) name:kBIDContentManagerContentDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newDataStartedDownloading:) name:kBIDContentManagerStartedDownloadingContent object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentAlreadyUpToDate) name:kBIDContentUpToDate object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentStartingSync) name:kBIDContentStartingSync object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentEndingSync) name:kBIDContentEndingSync object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(singleDownloadFinished) name:kBIDFinishedDownloadingSingleContent object:nil];
    self.navigationController.navigationBarHidden = NO;
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Sync"
                                                                    style:UIBarButtonItemStyleDone target:self action:@selector(Sync)];
    self.navigationItem.leftBarButtonItem = leftButton;
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Display Mode"
                                                                   style:UIBarButtonItemStyleDone target:self action:@selector(dismissSelf)];
    self.navigationItem.rightBarButtonItem = rightButton;

    self.navigationItem.title = @"Content Manager";
    self.navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_navigationBar];
    [self.navigationBar pushNavigationItem:self.navigationItem animated:NO];

}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

}
-(void)layoutNavigationBar{
    if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)
    {
    self.navigationBar.frame = CGRectMake(0, self.tableView.contentOffset.y, self.view.frame.size.width, self.topLayoutGuide.length + 44);
    }
    else
    {
        self.navigationBar.frame = CGRectMake(0, self.tableView.contentOffset.y, self.view.frame.size.height, self.topLayoutGuide.length + 44);
    }
    NSLog(@"width: %f", self.view.frame.size.width);
    NSLog(@"height: %f", self.view.frame.size.height);
    self.tableView.contentInset = UIEdgeInsetsMake(self.navigationBar.frame.size.height, 0, 0, 0);
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //no need to call super
    [self layoutNavigationBar];
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [self layoutNavigationBar];
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

}
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self layoutNavigationBar];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




/*
#pragma mark - Navigation

// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

 */
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.navigationBarHidden = YES;

}
-(void)newDataStartedDownloading: (NSNotification *)notif
{
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    _hud.labelText = @"Downloading...";
    _hud.detailsLabelText = [NSString stringWithFormat:@"1/%@",[notif.userInfo objectForKey:@"downloadFileNumber"]];

}
-(void)singleDownloadFinished
{
    NSString *currentText = _hud.detailsLabelText;
    NSArray *subStrings = [currentText componentsSeparatedByString:@"/"];
    NSInteger downloadsPlusOne = [[subStrings objectAtIndex:0] integerValue]+1;
    NSString *newTextForLabel = [NSString stringWithFormat:@"%d/%@", downloadsPlusOne, [subStrings objectAtIndex:1]];
    _hud.detailsLabelText = newTextForLabel;
}
-(void)newDataFinishedDownloading
{
    _thereIsNewInfo = TRUE;
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [self.tableView reloadData];
    [[NSNotificationCenter defaultCenter] postNotificationName:kBIDnewDownloadedContentReadyToBeDispayedNotification object:nil userInfo:nil];

}
-(void)contentAlreadyUpToDate
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sync Alert"
                                                    message:@"Files Are Already Up To Date"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles: nil];
    [alert show];

}
-(void)contentStartingSync
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"Syncing...";

}
-(void)contentEndingSync
{
     [MBProgressHUD hideHUDForView:self.view animated:YES];

}
-(void)Sync
{
    [AppDelegate.appContentManager downloadContent];
}
-(void)dismissSelf
{
    if (![AppDelegate.appContentManager subsetArrayFromFileArrayWithNonVidContentThatShouldDisplay] && ![AppDelegate.appContentManager subsetArrayFromFileArrayWithVideoContentThatShouldDisplay]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Files to Display"
                                                        message:@"Please update or enable content"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        return;
    }
    else if ([AppDelegate.appContentManager subsetArrayFromFileArrayWithNonVidContentThatShouldDisplay])
    {
        [self dismissViewControllerAnimated:YES completion:Nil];

    }
    else
    {
    [self performSegueWithIdentifier:@"goToVideos" sender:self];
    }
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"goToVideos"])
    {
        ((BIDViewController *)segue.destinationViewController).stackedByManager = TRUE;
    }

}

@end
4

1 に答える 1

0

向きの変更時にデータをリロードする必要はありませんが、テーブルをリロードする場合は、バックグラウンド ダウンロードの完了後、向きが変更された場合にのみ [myTable reloadData] を呼び出してみてください (orient.change でこれに bool を設定できます)。

于 2013-12-19T10:02:02.857 に答える