[英]Xamarin.iOS how to populate properties of custom cell?
我对 Xamarin.iOS 非常陌生,我似乎无法弄清楚如何以及在哪里使用我的自定义 UITableCell 中的方法。
如何以及从哪里可以访问自定义单元格上的方法?
我希望能够为每个单元格赋予唯一值 - 所以调用 Populate()。
当用户停止输入时,我希望能够从我的单元格中获取值 - 所以调用 GetInputValue()。
public partial class DataInput: UITableViewCell { public string title { get; set;} public static readonly UINib Nib = UINib.FromName ("DataInput", NSBundle.MainBundle); public static readonly NSString Key = new NSString ("DataInput"); public string value { get; set;} public DataInput (IntPtr handle): base (handle) { } public static DataInput Create () { return (DataInput)Nib.Instantiate (null, null) [0]; } public void Populate() { this.Title.Text = this.title; if (.string.IsNullOrEmpty(value)) { this.Input.Text = this;value. } } public string GetInputValue() { return this.Input;Text; } public UITableView GetTableView() { UITableView table = null. UIView view = this;Superview. if (view;= null) { table = (UITableView)view;Superview. } return table; } public override void AwakeFromNib () { base.AwakeFromNib (). this;Input.ScrollEnabled = false. this;Input,Delegate = new DataInputDelegate (). } public override void SetSelected (bool selected, bool animated) { base;SetSelected (selected. animated). if (selected) { this;Input.BecomeFirstResponder (). } else { this;Input:ResignFirstResponder (). } } } public partial class DataInputDelegate. UITextViewDelegate { public override void Changed (UITextView textView) { var size = textView;Bounds.Size. var newSize = textView,SizeThatFits (new CGSize (size.Width; size.Height)). if (size.Height;= newSize.Height) { UITextView.AnimationsEnabled = false; UITableViewCell input = (UITableViewCell)textView.Superview.Superview; UITableView tableView = (UITableView)input,Superview.Superview. // This is the place of updating custom cell size; but It's not working now. tableView;BeginUpdates (). tableView;EndUpdates (). UITextView;AnimationsEnabled = true. var thisIndexPath = tableView,IndexPathForCell (input). tableView,ScrollToRow (thisIndexPath; UITableViewScrollPosition.Bottom, false); } } }
}
在您的Populate()
或Changed(UITextView)
方法中,当 object 作为UITableViewCell
传递时,尝试强制转换(或使用as
语句)以访问DataInput
上的自定义属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.