2017-12-11 11 views
0

だから私はiPhone版のTableviewでViewControllerを作成し、素晴らしい作品を作成しました。Popoverテーブルビューでセルを選択した後にUILabelがリフレッシュされない

iPad版では、テキストだけがあればテーブルビュー全体を画面全体に表示することはできません。だからiPadのストーリーボードでは、カスタムViewControllerにテーブルビューで接続されたボタンをメインビューコントローラに作成し、代わりにポップオーバーとして開きます。

開いていると、データがViewViewを使用してメインビューに渡されています。コンソールでは、ラベルが更新されているのが見えますが、画面上ではラベルは更新されません。

私がデータを取得するために使用した方法で試した[self.view layoutIfNeeded]、他の回答で示唆された一部の人々としてアルファを変更します。私はviewWillAppearがまったく呼び出されないことに気づいた。 didSelectRowAtIndexにメインのvc viewWillAppearを設定しようとしました...

私は別の画面に移動して戻ってくると、もちろんラベルが更新されます。

ここでは、ポップオーバーでセルを選択したときに、テーブルビューでView Controllerを解除する方法を示します。

[self dismissViewControllerAnimated:YES completion:^{ 
    [vc viewWillAppear:YES]; 
    [vc.view layoutIfNeeded]; 
    [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; 
}]; 

メインビューコントローラーが更新されないようにすることは控えていますか?

これは、ポップオーバーのメソッドです:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 


UIStoryboard * storyboard = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 
[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] : 
[UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 
(ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] : 
(ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{   
    if(searching){ 
     if ([copyListOfItems count]>0) { 

      NSLog(@"Search Results Selected %@", [copyListOfItems objectAtIndex:indexPath.row]); 

      [vc.lbl_specialties setText:[copyListOfItems objectAtIndex:indexPath.row]]; 
     } 
    } 
    else { 

     self.appDelegate.selectedSpecialty = [arrUsers objectAtIndex:indexPath.row]; 

     NSLog(@"Selected %@", self.appDelegate.selectedSpecialty); 


    } 
     [self dismissViewControllerAnimated:YES completion:^{ 
      [vc viewWillAppear:YES]; 
      [vc.view layoutIfNeeded]; 
      [vc updateSpecialtyText:[arrUsers objectAtIndex:indexPath.row]]; 

     }]; 
    } 
} 

これは、上記と呼ばれているビューコントローラのメソッドです。代わりに

[self dismissViewControllerAnimated:YES completion:^{ 
    [vc viewWillAppear:YES]; 
    [vc.view layoutIfNeeded]; 
    [vc updateText:[arrUsers objectAtIndex:indexPath.row]]; 
}]; 

の私の意見では

-(void)updateSpecialtyText:(NSString*)text 
{ 
    [super viewWillAppear:YES]; 

    NSLog(@"text to update %@", text); 
    [self.lbl_specialties layoutIfNeeded]; 
    [self.view layoutIfNeeded]; 
    [self.lbl_specialties setText:text]; 

    NSLog(@"text updated %@", self.lbl_specialties.text); 

} 
+0

「vc」の値はどこで得られましたか? – trungduc

+0

@trungducメインViewControllerをインスタンス化します。 'ViewController * vc =(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)? (ViewControllerを*)[ストーリーボードinstantiateViewControllerWithIdentifier: "ViewControlleriPad" @]: (ViewControllerを*)[ストーリーボードinstantiateViewControllerWithIdentifier: "ViewControllerを" @]; ' – GunplaGamer

+0

は、あなたがそれ原因編集した質問@trungduc – trungduc

答えて

1

ViewControllerUINavigationControllerに埋め込まれている場合は、代わりに以下のコードを使用し、

[(ViewController *)self.presentingViewController updateText:[arrUsers objectAtIndex:indexPath.row]]; 
[self dismissViewControllerAnimated:YES completion:nil]; 

を試してみてください。

[(ViewController *)[(UINavigationController *)self.presentingViewController topViewController] updateText:[arrUsers objectAtIndex:indexPath.row]]; 
[self dismissViewControllerAnimated:YES completion:nil]; 
+0

「***キャッチされていない例外のため、アプリケーションを終了しています」NSInvalidArgumentException '、理由:' - [UINavigationController updateSpecialtyText:]:インスタンス0x152829600に送信された認識できないセレクタ ' – GunplaGamer

+0

' ViewController'ビューコントローラ – trungduc

+0

私はストーリーボードでやった。私はViewControllerにボタンを配置し、それをControlで選択してSpecialViewControlerにドラッグし、 'Pop As Present'を選択しました。 – GunplaGamer

関連する問題