0
解決方法はかなりシンプルかもしれませんが、これらのビューを配置する際に問題があります。Monotouch - UILabelsを相互に下にプログラムで作成するためにforループを使用する
私はUITableViewCell
の範囲内でUILabels
を動的に作成しようとしています。コンパイル時にはUILabels
の数は不明です。
私のデータリストのサイズに基づいて、新しいUILabel
を作成し、リストの各インデックスのデータをそれぞれUILabel
に入力したいとします。
これらはUITableViewCell
の内部に作成されているため、セルのTextLabel
の下に配置してください。
現在のところ、私の新しいUILabels
はすべて、お互いの上に重なっており、TextLabel
の上に積まれており、正しく配置されていないようです。だからここでの回答に基づいて
public void UpdateCell(List<Records> allRecords,List<string> otherInfo)
{
try{
UILabel label = new UILabel();
myRecords = allRecords;
for(int i = 0; i < myRecords.Count;i++)
{
if(i == 0)
//Position the first one below the cell's TextLabel
{
string time = myRecords[i].ResponseTime;
label.Frame = new CoreGraphics.CGRect(TextLabel.Frame.X + 10,TextLabel.Frame.Y + TextLabel.Frame.Height + 10,ContentView.Frame.Width,19);
label.Font = UIFont.FromName ("HelveticaNeueLTStd-ThCn", 18f);
label.TextColor = UIColor.DarkGray;
label.Text = string.Format("- {0}, {1}",otherInfo[i],time);
ContentView.AddSubview(label);
}else{
string responseTime = myRecords[i].ResponseTime;
//Position subsequent views below the first label
UILabel label1 = new UILabel();
label1.Frame = new CoreGraphics.CGRect(label.Frame.X,label.Frame.Bottom + 5,ContentView.Frame.Width,19);
label1.Font = UIFont.FromName ("HelveticaNeueLTStd-ThCn", 18f);
label1.TextColor = UIColor.DarkGray;
label1.Text = string.Format("- {0}, {1}",otherInfo[i],responseTime);
ContentView.AddSubview(label1);
}
}
}
}catch(Exception ex)
{
Console.WriteLine (ex.Message + ex.StackTrace);
}
}