My TableViewセルにボタンがあります。クリックすると、セルを展開します。展開するには、ボタンをクリックして行の高さを変更して行をリロードします。しかし、ある行が展開され、次に別の行を展開しようとすると、その動作は期待通りにはなりません。クリックされた行ではなく、以前に展開された行が閉じます。ios:UITableVIewCellが期待どおりに機能しない
また、時にはボタンを2回クリックして展開する必要があります。
public class ProgramMeasurementDetailsTableViewSource : UITableViewSource
{
List<ProgramMeasurementDetail> mList;
string HeaderIdentfier = "programMeasurementDetailsHeader";
string CellIdentifier = "programMeasurementDetailsCell";
int TAG_CHECKBOX = 61;
int TAG_LABEL_VITAL_NAME = 62;
int TAG_LABEL_GOAL = 63;
int TAG_BUTTON_EDIT = 64;
int TAG_VIEW_HEADER_COLUMN_SEPARATOR = 66;
int TAG_VIEW_ROW_COLUMN_SEPARATOR = 65;
List<bool> expandStatusList = new List<bool>();
UITableView tableView;
public ProgramMeasurementDetailsTableViewSource(List<ProgramMeasurementDetail> mList, UITableView tableView)
{
this.tableView = tableView;
this.mList = mList;
for (int i = 0; i < mList.Count; i++)
expandStatusList.Add(false);
}
public override nint NumberOfSections(UITableView tableView)
{
return 1;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return mList.Count;
}
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
return 32;
}
public override nfloat GetHeightForRow(UITableView tableView, Foundation.NSIndexPath indexPath)
{
if (expandStatusList[indexPath.Row])
return 70;
else
return 32;
}
public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier);
}
CheckBox checkBox = (CheckBox)cell.ViewWithTag(TAG_CHECKBOX);
UILabel vitalNameLabel = (UILabel)cell.ViewWithTag(TAG_LABEL_VITAL_NAME);
UILabel goalLabel = (UILabel)cell.ViewWithTag(TAG_LABEL_GOAL);
UIButton editGoalButton = (UIButton)cell.ViewWithTag(TAG_BUTTON_EDIT);
editGoalButton.TouchUpInside += (object sender, EventArgs e) =>
{
expandStatusList[indexPath.Row] = !expandStatusList[indexPath.Row];
tableView.ReloadRows(new Foundation.NSIndexPath[] { indexPath }, UITableViewRowAnimation.Automatic);
};
.....
return cell;
}
}
私は、その後、IF(セル== null)の内部での取り扱いボタンクリックイベントを移動しようとしたが、ボタンをクリック/拡大がまったく機能していません。ブレークポイントを置くと、その部分は決して実行されないようです。
私はストーリーボードでセルレイアウトを設計しました。
私は今この問題にかなり苦しんでいます。どんな助けもありがとうございます。
私はストーリーボードを使用して細胞を設計すべきではありませんか?今私はストーリーボードで設計されたセルを持っています。 CustomCellクラスでセルのデザインとして使用することは可能ですか? – HeisenBerg
ストーリーボードのセルも使用できます。 'TableView Cell Style'が' Custom'に設定されていることを確認し、クラス名を付けてください。 Xamarinはカスタムクラス用の '.cs'ファイルを生成します。このチュートリアルの最初の部分では、コードビハインドファイルを生成する方法を説明します。https://developer.xamarin.com/guides/ios/user_interface/tables/autosizing-row-height/ – pnavk
ここでは、TouchUpinsideボタンを定義しますカスタムセルクラスを使用して?カスタムセルクラスに入れますか?はいの場合は、そこからテーブルビュー行をリロードするにはどうすればよいですか? – HeisenBerg