2012-05-12 2 views
0

Я очень новичок в разработке XCode и Monotouch. Я пытаюсь добавить несколько вкладок в корневом представлении (приложение Master-Detail). Я использую Mono для разработки и xCode 4 для дизайна пользовательского интерфейса. Например, на одной вкладке отображается список сотрудников, а на другой вкладке отображается список отделов.Несколько вкладок в 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 при выполнении нативного кода»

Первого списка населенного нормально.

ответ

0

Я думаю, что объекты 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

Thanks holmes .. хорошо работает :) –

Смежные вопросы