[英]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 ~ 希望帮助〜
Sorry i have never use Xamarin before 抱歉,我以前从未使用过Xamarin
so i think this is a bad way to implement ... 所以我认为这是一种不好的实现方式...
but it look work 但是看起来不错
[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;
}
}
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.