UITableViewでタップしたセルをViewControllerで取得したいのですが、RowSelected()が呼ばれないようです。
IUITableViewDelegateのメソッドだと思われますが、なぜ呼ばれないのでしょうか?
c#
1 public partial class ViewController : UIViewController, IUITableViewDelegate 2 { 3 4 public ViewController (IntPtr handle) : base (handle) 5 { 6 } 7 8 public override void ViewDidLoad () 9 { 10 base.ViewDidLoad (); 11 12 UITableView tableView = new UITableView() 13 { 14 Frame = new CGRect(0, 0, 500, 500), 15 BackgroundColor = UIColor.Blue, 16 RowHeight = 100, 17 Delegate = this, 18 }; 19 20 tableView.RegisterClassForCellReuse(typeof(SampleViewCell), nameof(SampleViewCell)); 21 tableView.Source = new SampleViewSource(); 22 23 View.AddSubview(tableView); 24 } 25 26 public void RowSelected(UITableView tableView, NSIndexPath indexPath) 27 { 28 Console.WriteLine("RowSelected"); 29 View.BackgroundColor = UIColor.Red; 30 } 31 32 }
c#
1 class SampleViewCell : UITableViewCell 2 { 3 public SampleViewCell(IntPtr handle) : base(handle) 4 { 5 UIView view = new UIView() 6 { 7 Frame = new CGRect(0, 0, 100, 100), 8 BackgroundColor = UIColor.Green, 9 }; 10 AddSubview(view); 11 } 12 13 }
c#
1 class SampleViewSource : UITableViewSource 2 { 3 public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 4 { 5 var cell = (SampleViewCell)tableView.DequeueReusableCell(nameof(SampleViewCell), indexPath); 6 return cell; 7 } 8 9 public override nint RowsInSection(UITableView tableview, nint section) 10 { 11 return 10; 12 } 13 }
◆環境
▼Windows 10
Visual Studio Community 2017 Version 15.9.11
Xamarin 4.12.3.83
Xamarin.iOS and Xamarin.Mac SDK 12.4.0.64
▼Mac mini(Late 2014)
macOS Majave 10.14.4
Xcode 10.2.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/14 16:14