私は解決策を持っています。私はプログラミングパターンやガイドラインに違反していないことを正しく認識しているかどうか、誰かが確認してください。
要約:TableSource-Classでは、ストーリーボードにアクセスし、実際に表示されているコントローラと同じコントローラを動的に作成して表示します。しかし、新しいものを提示する前に、私は他のソースクラスを宣言します。したがってTableViewはアドレス帳とアドレスカードの表示に使用され、UIViewControllerはカードデータの表示に使用されます。これらの2つのコントローラは、segueを介して接続されています。ここで
は私のコントローラとの両方のソース・クラスです:
AddressbooksController.cs
public AddressbooksController (IntPtr handle) : base (handle)
{
displayModel = "addressbooks";
}
private void loadAddressbooks()
{
var AppDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;
addressbooks = AppDelegate.api.DeserializeEntities<YAddressbook>(Task.Run(async() => await AppDelegate.api.Get("Yaddressbooks")).Result);
}
public void loadAddresscards()
{
var AppDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;
addresscards = AppDelegate.api.DeserializeEntities<Ycard>(Task.Run(async() => await AppDelegate.api.Get("Ycards")).Result);
}
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue(segue, sender);
// do first a control on the Identifier for your segu
if (segue.Identifier.Equals("segueShowAddress"))
{
var viewController = (AddresscardController)segue.DestinationViewController;
viewController.card = Card2Display;
}
}
public override void ViewDidLoad()
{
if (displayModel == "addressbooks")
{
loadAddressbooks();
tableView.Source = new AddressbooksTableSource(addressbooks.data, this);
this.NavigationController.Title = "Addressbücher";
}
else if (displayModel == "addresscards")
{
loadAddresscards();
tableView.Source = new AddresscardsTableSource(addresscards.data, this);
this.NavigationController.
}
base.ViewDidLoad();
}
AddressbooksTableSource
public class AddressbooksTableSource: UITableViewSource
{
private List<YAddressbook> addressbooks;
private string cellIdentifier = "AddressbooksCell";
private UINavigationController navigationController;
public AddressbooksTableSource(List<YAddressbook> books, AddressbooksController ab)
{
addressbooks = books;
this.navigationController = ab.ParentViewController as UINavigationController;
Console.WriteLine(ab.displayModel);
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine("Row selected" + addressbooks[indexPath.Row].displayname);
UIStoryboard Storyboard = UIStoryboard.FromName("Main", null);
AddressbooksController newab = Storyboard.InstantiateViewController("AddressbooksViewController") as AddressbooksController;
newab.displayModel = "addresscards";
navigationController.PushViewController(newab, true);
tableView.DeselectRow(indexPath, true);
}
....
}
AddresscardsTableSource
public class AddresscardsTableSource: UITableViewSource
{
private List<Ycard> addresscards;
UINavigationController navigationController;
AddressbooksController ab;
string cellIdentifier = "AddresscardCell";
public AddresscardsTableSource(List<Ycard> cards, AddressbooksController vc)
{
addresscards = cards;
navigationController = vc.ParentViewController as UINavigationController;
ab = vc;
//navigationController = tableview;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine("Row selected" + addresscards[indexPath.Row].carddata);
//UIStoryboard Storyboard = UIStoryboard.FromName("Main", null);
ab.Card2Display = addresscards[indexPath.Row];
ab.PerformSegue("segueShowAddress", indexPath);
//AddresscardController ab = Storyboard.InstantiateViewController("AddresscardViewController") as AddressbooksController;
//ab.TableView.Source = this;
//navigationController.PushViewController(ab, true);
tableView.DeselectRow(indexPath, true);
}
.....
}
それは動作します。しかし、私は正しくそれをやっていますか?ありがとう
どのようなカテゴリと記事をデータベースで定義し、実行中にそれらをフェッチするのですか? – Zbidi
私はこのデータをWAN/LAN経由のAPI経由で受け取ります。しかし、データを取得することはその問題ではありません。私はプログラム的にtableviewcontrollerをn個のサブカテゴリレベルと最終的なアーティクルレベルで再利用する方法を知らない。私はこのような考えをコンセプトに考えました:テーブルにデータを表示する。タッチ - >サブカテゴリレベル1を表示して、このテーブル(およびナビゲーションスタック)を再利用 - >タッチ - >表示 - >タッチ - >表示....最後に記事リスト - >タッチ - > UIViewControllerを記事詳細で読み込みます。これをコードでどうやって行うのですか?これは正しい方法ですか?あなたが理解したいと思っています。 – MikeRoss