UsiableViewSourceの下のNavigationController.PushViewControllerにアクセスする方法

StackOverflow https://stackoverflow.com//questions/23002029

  •  20-12-2019
  •  | 
  •  

質問

NavigationControllerクラス内のUITableviewSourceにアクセスできますか?

行選択では、他のUIControllerに移動したいです。

これは私のコードです、

public class RootTableSource : UITableViewSource
{
    IList<VendorDetails> tableItems;
    string cellIdentifier = "UIViewController";

    ReportsList reportList;
    AddNewReport addnewReport;

    public RootTableSource()
    {
    }

    public RootTableSource (IEnumerable<VendorDetails> items)
    {
        tableItems = items.ToList (); 
    }

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
    {
        tableView.DeselectRow (indexPath, true); 

        // Redirect to another UIController....
    }

    public VendorDetails GetItem (int id)
    {
        return tableItems [id];
    }
}
.

役に立ちましたか?

解決

私が自分のソースを作成するときにTableViewControllerへの参照を渡す方法です。その後、ソースはこの参照を使用して、その親のNavigationControllerにアクセスできます。

UITableViewController _parent;

public RootTableSource (IEnumerable<VendorDetails> items, UITableViewController parent)
{
    tableItems = items.ToList (); 
    _parent = parent;
}


public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
    tableView.DeselectRow (indexPath, true); 

    _parent.NavigationController.PushViewController(...);
}
.

他のヒント

AppDelegateでUnavigationControllerを持っていますか?

このような...

@property (strong, nonatomic) UINavigationController *navigationViewController;
.

その後、appdelegate delegate

からUinavigationControllerにアクセスできます。
#import "AppDelegate.h"

@implementation yourClassName

-(void)functionName{

    AppDelegate *appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];

    appdelegate.navigationViewController;  //your UINavigationController

    [appdelegate.navigationViewController pushViewController:yourUIViewController animated:YES];

}

@end
.

help〜

編集:

申し訳ありませんが

の前にxamarinを使いたことがない

だから私はこれが実装するのが悪い方法だと思います...

しかしそれは仕事を見て

appdelegates.cs

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{

    UIWindow window;
    HomeScreen home;
    public static UINavigationController navigation;
    //set navigation public and static      

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);
        home = new HomeScreen ();
        navigation = new UINavigationController(home);
        window.RootViewController =  navigation;
        window.MakeKeyAndVisible ();
        return true;
    }
}
.

yourclassname.cs

AppDelegate.navigation
//access navigation 
.

願い事...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top