Cómo acceder a NavigationController.PushViewController bajo UITableViewSource?

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

  •  20-12-2019
  •  | 
  •  

Pregunta

¿Cómo puedo acceder a NavigationController dentro de UITableviewSource la clase?

En la selección de la Fila quiero ir a otro UIController.

Este es mi código,

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];
    }
}
¿Fue útil?

Solución

La forma en la que hago esto es por los que pasa una referencia a la TableViewController cuando me cree mi Fuente.A continuación, la Fuente puede utilizar esta referencia al acceso de los padres de 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(...);
}

Otros consejos

tiene usted instancia UINavigationController en el AppDelegate ?

como esto...

@property (strong, nonatomic) UINavigationController *navigationViewController;

entonces usted debe puede acceder a UINavigationController de AppDelegate delegado

#import "AppDelegate.h"

@implementation yourClassName

-(void)functionName{

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

    appdelegate.navigationViewController;  //your UINavigationController

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

}

@end

deseo ayudar a ~

editar:

Lo siento, nunca uso Xamarin antes de

así que creo que esta es una mala manera de implementar ...

pero buscar trabajo

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 

deseo de ayudar de nuevo ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top