在表格视图中,禁用退回使得在尝试过度滚动表格视图后点击两次以检测didSelectRowAtIndexPath()
委托。启用跳出后,它会在滚动表格视图的开头和结尾处给出一个空白空间,并在单击该单元格时调用didSelectRowAtIndexPath()
委托。是否有任何方法可以修复单元格上的双击以在用户尝试滚动后选择它?
代码
的ViewController
public partial class MyViewController : UIViewController
{
public MyViewController() : base("MyViewController", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
sampletable.Source = new TableSource();
}
}
表格来源
public class TableSource :UITableViewSource
{
string[] data = new string[] { "one", "two", "three", "four", "five" };
string[] header = new string[] { "Header1", "Header2", "Header3", "Header4", "Header5" };
public TableSource()
{
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = (MyTableViewCell)tableView.DequeueReusableCell(MyTableViewCell.Key);
if (cell == null)
{
cell = MyTableViewCell.Create();
}
cell.data = data[indexPath.Row];
return cell;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine(header[indexPath.Section] + "->" + data[indexPath.Row]);
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return data.Length;
}
public override nint NumberOfSections(UITableView tableView)
{
return header.Length;
}
public override string TitleForHeader(UITableView tableView, nint section)
{
return header[section];
}
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
return 50;
}
}
细胞
public partial class MyTableViewCell : UITableViewCell
{
public static readonly NSString Key = new NSString("MyTableViewCell");
public static readonly UINib Nib;
public string data { get; set; }
static MyTableViewCell()
{
Nib = UINib.FromName("MyTableViewCell", NSBundle.MainBundle);
}
protected MyTableViewCell(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public static MyTableViewCell Create()
{
return (MyTableViewCell)Nib.Instantiate(null, null)[0];
}
public override void LayoutSubviews()
{
countLabel.Text = data;
}
}
我取消选中界面构建器中的Bounce,Bounce Vertical和Bounce Horizontal复选框
更新:原生iOS Swift版本代码