OK
ChrisNTR。私はこれを解決するために多くのものを試してきましたが、ChrisNTRは私の特定の問題に適切な解決策をもたらしました。私は彼の例のスニペットをここに示します:
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell("reuseThis");
if(cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, "reuseThis");
}
cell.TextLabel.Text = Convert.ToChar(dash.oneToHundred[indexPath.Row]).ToString();
var button = UIButton.FromType(UIButtonType.RoundedRect);
button.Frame = new System.Drawing.RectangleF(40f, 0f, 280f, 40f);
button.SetTitle(dash.oneToHundred[indexPath.Row].ToString(),UIControlState.Normal);
button.AddTarget (this, new Selector ("MySelector"), UIControlEvent.TouchDown);
button.Tag = indexPath.Row;
cell.ContentView.AddSubview(button);
return cell;
}
[Export ("MySelector")]
void ButtonEventHere (UIButton button)
{
Console.WriteLine ("Hello! - Button clicked = " + button.Tag);
Console.WriteLine (Convert.ToChar(dash.oneToHundred[button.Tag]).ToString());
}
短いと、ボタンに対応する値をボタンに渡します。これらの値の1つは、 'buttonEventHere'として定義したセレクタです([export( "MySelector")]に正しい名前が付いていることを確認してください)。 indexPath.Rowをbutton.Tagに渡してください。そのインデックスを使用して、どのボタンが押されたかを知り、それに応じてアクションを実行します。
もしあなたが私のように抱かれていたなら、これは役に立ちます。
あなたは正しいですが、それはとても醜いです! – skolima