C#IOS将事件处理程序设置为表行
本文关键字:设置 程序 事件处理 C#IOS | 更新日期: 2023-09-27 18:25:04
我使用的是UITableViewController。
我希望在触摸表中的特定行后重定向到另一个页面,而不是显示警报视图。
我有这个代码,但它不工作
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView("Row Selected", tableItems[indexPath.Row], null, "OK", null).Show();
tableView.DeselectRow (indexPath, true); // normal iOS behaviour is to remove the blue highlight
//call the next screen
if(this.accountRegistration== null) {
this.accountRegistration = new AccountRegistration();
}
this.NavigationController.PushViewController(this.accountRegistration, true);
}
我正在更改我的答案,因为我没有意识到你在使用UITableViewController。
在AppDelegate.cs文件中,您需要将rootNavigationController设置为新的UINavigationController:
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
UINavigationController rootNavigationController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
this.window = new UIWindow (UIScreen.MainScreen.Bounds);
//---- instantiate a new navigation controller
this.rootNavigationController = new UINavigationController();
this.rootNavigationController.PushViewController(new MyUITableViewController(), false);
//---- set the root view controller on the window. the nav
// controller will handle the rest
this.window.RootViewController = this.rootNavigationController;
this.window.MakeKeyAndVisible ();
return true;
}
....
从那时起,您的UITableViewController应该始终具有对此的引用。NavigationController。
此代码适用于
[注册("AppDelegate")]公共分部类AppDelegate:UIApplicationDelegate{//类级声明UIWindow窗口;UINavigationController根NavigationController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
this.window = new UIWindow (UIScreen.MainScreen.Bounds);
//---- instantiate a new navigation controller
this.rootNavigationController = new UINavigationController();
this.rootNavigationController.PushViewController(new MyUITableViewController(), false);
//---- set the root view controller on the window. the nav
// controller will handle the rest
this.window.RootViewController = this.rootNavigationController;
this.window.MakeKeyAndVisible ();
return true;
}