Comment accéder à NavigationController.PushViewController sous UITableViewSource?

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

  •  20-12-2019
  •  | 
  •  

Question

Comment puis-je accéder à NavigationController à l'intérieur de UITableviewSource de classe?

Sur sélection d'une Ligne, je veux accéder à un autre UIController.

C'est mon code,

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];
    }
}
Était-ce utile?

La solution

La façon dont je le fais c'est par le passage d'une référence à la TableViewController quand je crée ma Source.Ensuite, la Source peut utiliser cette référence pour accéder à ses parents 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(...);
}

Autres conseils

avez-vous d'instance UINavigationController dans AppDelegate ?

c'est comme ça...

@property (strong, nonatomic) UINavigationController *navigationViewController;

alors vous devriez peut accéder à UINavigationController de AppDelegate délégué

#import "AppDelegate.h"

@implementation yourClassName

-(void)functionName{

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

    appdelegate.navigationViewController;  //your UINavigationController

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

}

@end

souhaitez l'aide ~

edit:

Désolé, je n'ai jamais utiliser Xamarin avant

donc, je pense que c'est une mauvaise façon de mettre en œuvre ...

mais il regarde de travail

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 

souhaitez aider à nouveau ...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top