1

それで、

フォーム(基本的にはUITableView)があり、フォームが完成したら、画面の上部にある[完了]ボタンをクリックします。

クリックした後、データを別のtableView(別のtableViewControllerにあります)に追加する必要があります。このテーブルは、ナビゲーションコントローラー内にもあります。

[完了]ボタンを押した後、presentModalViewControllerを(新しいデータを含む)新しいTableViewにし、tableViewの上にナビゲーションコントローラーを配置する必要があります。

要約すると、次のようになります。

  • 完了ボタンはsomeTableViewControllerにあります。
  • dogTableViewControllerという別のtableViewにオブジェクトを追加する必要があります(簡単にするために「Dobby」という名前を追加しているとしましょう)。
  • データをリロードし、dogNavigationController内にdogTableViewControllerがある画面を表示します。
  • すべてのクラスが適切に参照され、含まれています。

[完了]ボタンがクリックされたときに-(IBAction)を貼り付けています。

-(IBAction) doneWithData: (UIBarButtonItem*) sender{


 UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[indicator sizeToFit];
indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                              UIViewAutoresizingFlexibleRightMargin |
                              UIViewAutoresizingFlexibleTopMargin |
                              UIViewAutoresizingFlexibleBottomMargin);

indicator.tag = 1;
[self.view addSubview:indicator];
[indicator setBackgroundColor:[UIColor clearColor]];
indicator.center = self.view.center;
indicator.hidden = FALSE;
[indicator startAnimating];

if (self.dogTableViewController == nil)
{
    DogTableViewController *temp = [[DogTableViewController alloc] init];
    self.dogTableViewController = temp;
    [temp release];
}

if (self.dogNavigationController == nil)
{
    DogNavigationController *temp = [[DogNavigationController alloc] init];
    self.dogNavigationController = temp;
    [temp release];
}

[self.dogTableViewController.dogArray addObject:@"Dobby"];
[self.dogTableViewController.tableView reloadData];

NSLog (@"%@", [self.dogTableViewController.dogArray objectAtIndex:0]); 
//Prints out "Null" //

[self presentModalViewController:dogNavigationController animated:YES];


[indicator release];

}

これをすべて実行して[完了]ボタンをクリックすると、

テーブルがない空のナビゲーション画面が表示されます。さらに、dogNavigationController画面にもいくつかのボタンがありました。何も見えない!!

私の目的は、画面をこの新しい画面(rootControllerではなくホーム画面)に転送することです。このタスクにはmodalViewControllerを使用する必要があると思いますか?別の画面にデータを転送するために他の方法を使用する必要があると思いますか?

psPushViewControllerを使用したくありません。

4

1 に答える 1

2

私はあなたがすべきだと思います

[self.navigationController popToRootViewControllerAnimated:YES];

それよりも。ルートビューコントローラを取得するには、次のようにします。

DogTableViewController * viewController = [self.navigationController.viewControllers objectAtIndex:0];
[viewController.dogArray addObject:aDog];

元の回答

ルートビューコントローラーを使用してナビゲーションコントローラーを初期化するべきではありませんか?

DogNavigationController *temp = [[DogNavigationController alloc] initWithRootViewController:self.dogTableViewController];
于 2011-06-08T15:51:19.990 に答える