2016-04-28 8 views
0

私はUIProgressViewを含むTableViewCellを持っていますが、コントローラのUIProgressViewに進捗値を設定してから等しくなります(self.progressBar = cell.progressBar)。 iOS8 & 9、UIではプログレスバーが0に止まっていますが、iOS7では動作します。助けを願っています。おかげで〜以下は、私のコードです:TableViewCellのUIProgressViewをコントローラ内のUIProgressViewと同じに設定する

@property (strong, nonatomic) IBOutlet UIProgressView *progressBar; 

- (void)viewDidLoad{ 
    [super viewDidLoad]; 
    self.timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target:self selector: @selector(handleProgressBar) userInfo: nil repeats: YES]; 
    [self.tableView reloadData]; 
} 

- (void) handleProgressBar{ 
    if(self.usedTime >= 300.0) 
    { 
     [self.timer invalidate]; 
     self.timer=nil; 
    } 
    else 
    { 
     self.usedTime += 1; 
     CGFloat progress = self.usedTime*(0.0033333333); 
     [self performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:progress] waitUntilDone:NO]; 
     if(self.usedTime>200){ 
     [self.progressBar setProgressTintColor:[UIColor redColor]];} 
    } 
} 

- (void)updateProgress:(NSNumber *)progress { 
    float fprogress = [progress floatValue]; 
    [self.progressBar setProgress:fprogress animated:YES]; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    switch (indexPath.section) { 
    case 0: 
     return [self configQuestionCellWithQIndex:self.pageIndex+1]; 
     break; 
    default: 
     return nil; 
     break; 
    } 
} 

- (QuestionTableViewCell*) configQuestionCellWithQIndex:(NSInteger)qIndex{ 
QuestionTableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"QuestionCell"]; 
[cell configCellWithQuestion:self.currentQuestion withQIndex:qIndex]; 
self.progressBar = cell.progressBar; 
return cell; 
} 
+0

progressBarを作成するQuestionTableViewCellのコードを追加できますか?なぜprogressBarプロパティにIBOutletを使用するのですか?また、configQuestionCellWithQIndex:メソッドへのupdateProgressの呼び出しを追加しようとします。 –

+0

ここにQuestionTableViewCell.hがあります:#import 。 @interface QuestionTableViewCell:UITableViewCell 。@プロパティ(強い、非原子的)IBOutlet UILabel * qIndex; 。@プロパティ(強い、非原子的)IBOutlet UILabel * title; 。@プロパティ(強い、非原子的)IBOutlet UIProgressView * progressBar; - (void)configCellWithQuestion:(Question *)q withQIndex:(NSInteger)qIndex; 。@ end – Winston

答えて

0

main thread

dispatch_async(dispatch_get_main_queue(), ^{ 

     cell.progressBar = self.progressBar; 

     //or 

     self.progressBar = cell.progressBar; 



}); 

であなたのUIのアップデートを実行し、メインスレッド上でUIの更新を行うようにしてください。

更新:

あなたは、細胞内のプログレスバーを更新するには、このような何かを行うことができ

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//... your code... 
cell.progressView.progress = progressValues[indexPath.row]; 
// ... 
return cell; 
} 

と、これはのように呼んで、

dispatch_async(dispatch_get_main_queue(), ^{ 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
OFPTableCell *cell = (OFPTableCell*)[self tableView:self.tableViewCache cellForRowAtIndexPath:indexPath]; 
progressValues[indexPath.row] = (double)totalBytesWritten/(double)totalBytesExpectedToWrite; 
[self.tableViewCache reloadData]; 
}); 

は詳細についてはthis linkを参照してください。

これは役に立ちます:)

+0

こんにちは、ライオン、助けてくれてありがとう!!しかし、私はこれの初心者ですから、もう一度説明してもらえますか? – Winston

+0

また、実際にはviewDidLoadで関数を実行していて、handleForgressBar関数を繰り返すためのタイマーを使用しているので、cellForRowAtIndexPathでそれを設定する方法はありますか? – Winston

+0

は私が答えで与えたリンクを参照してください – Lion

0

だけで簡単に考えた - あなたはラインを交換しようとしている:

self.progressBar = cell.progressBar; 

をして:

cell.progressBar = self.progressBar; 

それはそれを修正する場合は、私ができますiOS7で動作する方法はわかりますが、iOS8やiOS9では動作しません。

また、ViewControllerとUITableViewCellでUIProgressViewの異なるインスタンスを使用し、updateProgress:メソッドの通知を使用してセル内のUIProgressViewを更新することもできます。

+0

こんにちは、Siburb、cell.progressBar = self.progressBarに変更すると、iOS7も動作しません。何か案が?はい、私は[self.progressBar setProgress:fprogress animated:YES]を使用します。進捗状況をself.progressBarに設定することができますが、現在はセル内のプログレスバーを更新できると思いますので、UIに固執していますか? – Winston

関連する問題