Come accedere a NavigationController.PushViewController sotto UvibilityViewsource?

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

  •  20-12-2019
  •  | 
  •  

Domanda

Come posso accedere a NavigationController all'interno della classe UITableviewSource?

On Row Selection Voglio navigare su un altro UIController.

Questo è il mio codice,

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];
    }
}
.

È stato utile?

Soluzione

Il modo in cui lo faccio è passare un riferimento al tableviewcontroller quando creo la mia fonte.Quindi la fonte può utilizzare questo riferimento per accedere alla navigazione del genitoreController.

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(...);
}
.

Altri suggerimenti

Hai istanza uinavigationcontroller in AppDelegate?

Come questo ...

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

Allora dovresti accedere a UinavigationController da AppDelegate Delegate

#import "AppDelegate.h"

@implementation yourClassName

-(void)functionName{

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

    appdelegate.navigationViewController;  //your UINavigationController

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

}

@end
.

Aiuto desiderato ~

Modifica:

Scusa non ho mai usato xamarin prima

Quindi penso che questo sia un brutto modo per implementare ...

Ma sembra un lavoro

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 
.

Desideri Aiuto di nuovo ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top