我有一个带有自定义单元格的TableView,单元格中有一个标签和一个文本框。我想在选中该行时关注文本框。RowSelected在TableCell中编辑TextField
任何人知道如何在这段代码解决这个问题:
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
//EDIT TEXTFIELD FROM SELECTED ROW
}
我的文本框确实是一个自定义单元格类。 我试过这个:
CustomCell cell = tableView.CellAt (indexPath) as CustomCell;
cell.textField.BecomeFirstResponder();
但是textField永远找不到。
这是我CustomCell类:
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Forms.iOS
{
public class CustomCell : UITableViewCell
{
UITextField textField;
UILabel label;
public CustomCell (NSString cellId) : base (UITableViewCellStyle.Value1, cellId)
{
textField = new UITextField();
label = new UILabel();
ContentView.Add (label);
ContentView.Add (textField);
}
public void UpdateCell (string textFieldValue, string labelValue)
{
DetailTextLabel.Text = "Dit is echt nutteloze tekst maar geen idee waarvoor ik dit hier nu neer zet maar zodat het in ieder geval te veel is.";
textField.Placeholder = textFieldValue;
TextLabel.Text = labelValue;
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
DetailTextLabel.Hidden = true;
RectangleF detailFrame = DetailTextLabel.Frame;
textField.Frame = detailFrame;
}
}
}
为了任何人在看这个。 UITextField textField;需要公开才能在课堂以外访问(或者有吸气)。 – Hobsie