How to access NavigationController.PushViewController under UITableViewSource?
Question
How can I access NavigationController
inside UITableviewSource
class?
On Row selection I want to navigate to another 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];
}
}
Solution
The way I do this is by passing a reference to the TableViewController when I create my Source. Then the Source can use this reference to access it's parent's 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(...);
}
OTHER TIPS
have you instance UINavigationController in AppDelegate ?
like this...
@property (strong, nonatomic) UINavigationController *navigationViewController;
then you should can access UINavigationController from 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
wish help ~
edit:
Sorry i have never use Xamarin before
so i think this is a bad way to implement ...
but it look work
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
wish help again ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow