UIROVINGCOLTOLLER.PUSHVIEWCONTROLLER에 액세스하는 방법 UITableViewSource에서?
문제
NavigationController
클래스에서 UITableviewSource
에 어떻게 액세스 할 수 있습니까?
행 선택에서 다른 UIController
로 이동하려는
이 코드입니다.
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];
}
}
. 해결책
제가하는 방법은 내 소스를 만들 때 TableViewController에 대한 참조를 전달하는 것입니다.그런 다음 소스는이 참조를 사용하여 부모의 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(...);
}
. 다른 팁
AppDelegate의 UINAvigationController 인스턴스를 사용 하시겠습니까?
다음과 같이 ...
@property (strong, nonatomic) UINavigationController *navigationViewController;
.
AppDelegate Delegate
에서 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
.
소원 도움말 ~
편집 :
죄송합니다.
전에 xamarin을 사용하지 않았습니다.그래서 이것은 이것이 구현하는 나쁜 방법이라고 생각합니다 ...
하지만 작동하는 것
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
.
다시 한 번 도움이 필요합니다 ...
제휴하지 않습니다 StackOverflow