我有一個帶有自定義單元格的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