2012-01-07 7 views
0

MonoTouch C#アプリケーションで、ユーザーがレストランを検索できるように画面を作成しようとしています。ユーザーは、近く、どこにいても、最近訪問したレストランを検索することができます。これらの3つのオプションは、セグメント化されたコントロールとして表示されます。ユーザーがセグメント化されたコントロールのアイテムをクリックすると、表示されるビューが切り替わります。つまり、各オプションは独自のビューを表します。MonoTouchビューとコントローラの操作

ユーザーがレストランをクリックしたときに詳細が表示されるように、各ビューには独自のテーブルビューコントローラが必要です。ここからわかるように、ここに示すアプローチを実装する必要があります。http://www.alexyork.net/blog/post/UINavigationController-with-MonoTouch-Building-a-simple-RSS-reader-Part-1.aspx

私の問題は、コントローラをビューに追加する方法がわからないことです。私のシナリオでは、各UIView(各分割コントロール項目に1つ)にUITableViewControllerを追加する必要があると考えています。これは可能ですか?もしそうなら、どうですか?それが不可能な場合は、目標を達成するためにどうすればよいですか?これは簡単だと思われますが、私は途方もないようで、何かを誤解しています。ここでのviewDidLoadイベントがヒットしたとき、私は呼んでいる方法は次のとおりです。

private void LoadViews() 
{ 
    int subViewHeight = 320; 

    #region Nearby View 

    RectangleF nearbyRectangle = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, subViewHeight); 
    this.nearbyView = new UIView(nearbyRectangle); 
    this.nearbyView.BackgroundColor = UIColor.Blue; 

    this.nearbyTableViewController = new NearbyTableViewController(IntPtr.Zero); 
    this.NavigationController.PushViewController(nearbyTableViewController, false); 
    this.View.Add(nearbyView); 

    #endregion Nearby View 

    #region Elsewhere View 

    RectangleF elsewhereRectangle = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, subViewHeight); 
    this.elsewhereView = new UIView(elsewhereRectangle); 
    this.elsewhereView.Hidden = true; 
    this.elsewhereView.BackgroundColor = UIColor.Green; 

    // Add the search text field 
    UITextField searchElsewhereTextField = new UITextField(); 
    searchElsewhereTextField.BorderStyle = UITextBorderStyle.RoundedRect; 
    searchElsewhereTextField.Frame = new RectangleF(20, 13, 200, 31); 
    searchElsewhereTextField.Placeholder = "query"; 
    this.elsewhereView.AddSubview(searchElsewhereTextField); 

    // Add the search button 
    UIButton searchButton = UIButton.FromType(UIButtonType.RoundedRect); 
    searchButton.Frame = new RectangleF((UIScreen.MainScreen.Bounds.Width - 90), 13, 70, 31); 
    searchButton.SetTitle("Search", UIControlState.Normal); 
    this.elsewhereView.AddSubview(searchButton); 

    // Add the results table 
    this.elsewhereTableView = new UITableView(new RectangleF(0, 52, 
UIScreen.MainScreen.Bounds.Width, subViewHeight-70), UITableViewStyle.Plain); 
    this.elsewhereTableView.Source = new NearbyListDataSource(this);   
    this.elsewhereView.AddSubview(elsewhereTableView); 

    this.View.Add(elsewhereView); 

    #endregion Elsewhere View 

    #region Recent View 

    RectangleF recentRectangle = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, subViewHeight); 
    this.recentView = new UIView(recentRectangle); 
    this.recentView.Hidden = true; 

    this.recentTableView = new UITableView(new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, subViewHeight), UITableViewStyle.Plain); 
    this.recentTableView.Source = new NearbyListDataSource(this);   
    this.recentView.AddSubview(recentTableView); 

    this.View.Add(recentView); 

    #endregion Recent View 
} 

はあなたの助けをありがとう!

答えて

1

通常、UIViewController間を移動する場合は、UINavigationControllerを使用して画面に「プッシュ」します。この場合、UINavigationControllerのUINavigationBar内にUISegmentedControlが必要です。

セグメント化されたコントロールで関連付けられたアイテムをクリックすると、上記のメソッドが呼び出され、適切なコントローラが表示されます。

基本的に、UIViewControllerはビューの「コンテナ」です。あなたは別のViewControllerのビューにのViewControllerのビューを追加したい場合は、カスタムコンテナの私のブログの記事をご覧ください:

http://blog.devnos.com/wont-somebody-please-think-of-the-children

+0

こんにちは、私はちょうどの質問に私のコードを追加しました。ご回答いただきありがとうございます。私はまだ問題があります。私のコードを見直し、私が間違っていることを教えてください。私はこれで完全に挫折しています。ありがとうございました! –

+0

希望の動作をコードの数行に減らすことができないより複雑なケースでは、レビューのために小さな自己完結型のサンプルアプリケーションを作成してください。 – Anuj

関連する問題