rootview中的多个选项卡

问题描述:

我对XCode和Monotouch开发非常陌生。我试图在根视图(Master-Detail应用程序)中添加多个选项卡。我使用Mono进行开发,使用xCode 4进行UI设计。例如,一个选项卡显示员工列表,另一个选项卡显示部门列表。rootview中的多个选项卡

我删除了rootviewController.xib文件中的默认表视图,并用tabbedview替换,但我不能为每个选项卡工作获取新的表视图。

如果有人能告诉我正确的做法,我将不胜感激。

已更新:我使用下面的代码添加2个选项卡和2个表视图。一是举办“证券”,另一个举办“指示灯”

using System; 
using System.Drawing; 

using MonoTouch.Foundation; 
using MonoTouch.UIKit; 
using System.Collections.Generic; 

namespace ChartQ 
{ 
public partial class RootViewController : UITabBarController 
{ 
    public DetailViewController DetailVC { get; set; } 

    private List<SecurityInfo> listSecInfo = new List<SecurityInfo>(); 
    private List<Indicator> listIndicator = new List<Indicator>(); 
    public RootViewController() : base ("RootViewController", null) 
    { 
     this.Title = NSBundle.MainBundle.LocalizedString ("Securities", "Securities"); 
     //this.ClearsSelectionOnViewWillAppear = false; 
     this.ContentSizeForViewInPopover = new SizeF (100f, 200f); 
     //this.ContentSizeForViewInPopover = new SizeF (320f, 600f); 

     // Custom initialization 
    } 

    public override void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 
     //Read data from Database.. 
     UITableViewController secController = new UITableViewController(); 
     UITableViewController IndiController = new UITableViewController(); 

     this.AddChildViewController(secController); 
     this.AddChildViewController(IndiController); 
     SQLLiteDatabase db = new SQLLiteDatabase(); 
     listSecInfo = db.ReadSecurities(); 
     listIndicator = db.ReadIndicator(); 
     //TableView.Source = new SecuritiesDataSource (this); 
     secController.TableView.Source = new SecuritiesDataSource (this); 
     secController.TableView.SelectRow (NSIndexPath.FromRowSection (0, 0), false, UITableViewScrollPosition.Middle); 

     IndiController.TableView.Source = new IndicatorDataSource (this); 
     IndiController.TableView.SelectRow (NSIndexPath.FromRowSection (0, 0), false, UITableViewScrollPosition.Middle); 


    } 

    public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
    { 
     // Return true for supported orientations 
     return true; 
    } 

    public override void DidReceiveMemoryWarning() 
    { 
     // Releases the view if it doesn't have a superview. 
     base.DidReceiveMemoryWarning(); 

     // Release any cached data, images, etc that aren't in use. 
    } 

    public override void ViewDidUnload() 
    { 
     base.ViewDidUnload(); 


     // Clear any references to subviews of the main view in order to 
     // allow the Garbage Collector to collect them sooner. 
     // 
     // e.g. myOutlet.Dispose(); myOutlet = null; 

     ReleaseDesignerOutlets(); 
    } 
    class SecuritiesDataSource : UITableViewSource 
    { 
     static NSString cellIdentifier = new NSString ("CellId"); 
     RootViewController controller; 

     public SecuritiesDataSource (RootViewController controller) 
     { 
      this.controller = controller; 
     } 

     // Customize the number of sections in the table view. 
     public override int NumberOfSections (UITableView tableView) 
     { 
      return 1; 
     } 

     public override int RowsInSection (UITableView tableview, int section) 
     { 
      return controller.listSecInfo.Count; 
     } 

     public override string TitleForHeader (UITableView tableView, int section) 
     { 
      return "Securities"; 
     } 

     // Customize the appearance of table view cells. 
     public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
     { 
      string cellIdentifier = "Cell"; 
      var cell = tableView.DequeueReusableCell (cellIdentifier); 
      if (cell == null) { 
       cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier); 
       //Add in a detail disclosure icon to each cell 
       cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton; 
      } 

      // Configure the cell. 
      var sInfo = controller.listSecInfo [indexPath.Row]; 
      cell.TextLabel.Text = String.Format ("{0}",sInfo.SecCode); 
      cell.DetailTextLabel.Text = sInfo.SecName; 

      return cell; 
     } 


     private void InfoAlert (string msg) 
     { 
      using (UIAlertView av = new UIAlertView("Info", msg, null, "OK", null)) { 
       av.Show(); 
      } 
     } 

     public override void RowSelected (UITableView tableView, NSIndexPath indexPath) 
     { 
      var sInfo = controller.listSecInfo [indexPath.Row]; 

      controller.DetailVC.DrawChart(sInfo.SecID, sInfo.SecCode); 
     } 



    } 
    class IndicatorDataSource : UITableViewSource 
    { 
     static NSString cellIdentifier = new NSString ("CellId"); 
     RootViewController controller; 

     public IndicatorDataSource (RootViewController controller) 
     { 
      this.controller = controller; 
     } 

     // Customize the number of sections in the table view. 
     public override int NumberOfSections (UITableView tableView) 
     { 
      return 1; 
     } 

     public override int RowsInSection (UITableView tableview, int section) 
     { 
      return controller.listIndicator.Count; 
     } 

     public override string TitleForHeader (UITableView tableView, int section) 
     { 
      return "Indicators"; 
     } 

     // Customize the appearance of table view cells. 
     public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
     { 
      string cellIdentifier = "Cell"; 
      var cell = tableView.DequeueReusableCell (cellIdentifier); 
      if (cell == null) { 
       cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier); 
       //Add in a detail disclosure icon to each cell 
       cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton; 
      } 

      // Configure the cell. 
      var sInfo = controller.listIndicator [indexPath.Row]; 
      cell.TextLabel.Text = String.Format ("{0}",sInfo.DescriptiveName); 
      cell.DetailTextLabel.Text = sInfo.ShortName; 

      return cell; 
     } 



     private void InfoAlert (string msg) 
     { 
      using (UIAlertView av = new UIAlertView("Info", msg, null, "OK", null)) { 
       av.Show(); 
      } 
     } 

     public override void RowSelected (UITableView tableView, NSIndexPath indexPath) 
     { 
      var sInfo = controller.listIndicator [indexPath.Row]; 

      //controller.DetailVC.DrawChart(sInfo.SecID, sInfo.SecCode); 
     } 


    } 

} 

然而,当我点击第二个选项卡崩溃。

填充确定第一个列表我收到如下错误

“在执行本机代码得到了SIGSEGV”。

我认为UITableViewController对象正在收集并导致您的中止。创建secController和secController成员变量。

public partial class RootViewController : UITabBarController 
{ 
    UITableViewController secController; 
    UITableViewController IndiController; 

    public DetailViewController DetailVC { get; set; } 

... 

public override void ViewDidLoad() 
{ 
    base.ViewDidLoad(); 
    //Read data from Database.. 
    secController = new UITableViewController(); 
    IndiController = new UITableViewController(); 
+0

谢谢holmes ..效果不错:) –