简体   繁体   English

如何在UITableViewSource下访问NavigationController.PushViewController?

[英]How to access NavigationController.PushViewController under UITableViewSource?

How can I access NavigationController inside UITableviewSource class? 如何访问UITableviewSource类中的NavigationController

On Row selection I want to navigate to another UIController . 在行选择上,我想导航到另一个UIController

This is my 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];
    }
}

have you instance UINavigationController in AppDelegate ? 您在AppDelegate中实例化了UINavigationController吗?

like this... 像这样...

@property (strong, nonatomic) UINavigationController *navigationViewController;

then you should can access UINavigationController from AppDelegate delegate 那么您应该可以从AppDelegate委托访问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

wish help ~ 希望帮助〜

edit: 编辑:

Sorry i have never use Xamarin before 抱歉,我以前从未使用过Xamarin

so i think this is a bad way to implement ... 所以我认为这是一种不好的实现方式...

but it look work 但是看起来不错

AppDelegates.cs 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 yourClassName.cs

AppDelegate.navigation
//access navigation 

wish help again ... 希望再次帮助...

The way I do this is by passing a reference to the TableViewController when I create my Source. 我这样做的方法是在创建Source时传递对TableViewController的引用。 Then the Source can use this reference to access it's parent's NavigationController. 然后,Source可以使用此引用来访问其父级的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(...);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我从UITableViewSource单击RowSelected时如何打开UIViewController - how to open UIViewController when i click RowSelected from UITableViewSource 如何在NavigationController上启用/添加BackButton? - How to enable/add a BackButton on the NavigationController? 如何在UserControl的UserControl下访问控件 - How to access a control under the UserControl of UserControl 如何打开NavigationController的根并传递值? - How to open NavigationController's root and pass a value? Xamarin.IOS:UITableViewSource在设备上崩溃 - Xamarin.IOS: UITableViewSource crashes on device 如何直接在Windows下访问OPTICAL块设备 - How to access an OPTICAL block device directly under Windows 如何通过代码隐藏在DataTemplate下访问按钮? - How to access button under DataTemplate via code behind? 我如何在我的xaml的datagridtemplate列下的网格下的datepicker访问我的xaml.cs页? - how can i access datepicker under grid under datagridtemplate column in my xaml to my xaml.cs page?How will i get this 单击按钮后,对UITableViewSource中的单元格进行排序。 C#Xamarin - Sort cells in UITableViewSource after button clicked. c# Xamarin 我如何从C#中同一项目下的不同Windows窗体访问不同的组件? - How can i access the different component from different windows form which are under same project in c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM