前提・実現したいこと
初めての質問になります。
よろしくお願いします。
Xamarin.iOSで、記事一覧を表示するアプリを開発しております。
TableViewで、TableCellを設置し、Styleを「Custom」の設定にしています。
=>この後、左側にサムネ(ImageView)など、複数のコンテンツを設置するため、「Custom」。
そのCellの中に、Labelを配置して、試しに、5個表示することはできました。
Labelそのものに、「ほげほげ・・・・ほげほげ」をいれてあります。
ただし、そのLabelの文字数を多くした場合、2行目の半分から、切り落とされた状態になってしまいます。
TableCellの行が、自動調整されてないからかと、推測をしております。
自分で色々と調べてみて、「TableView.ReloadData()」など、試してみましたが、うまくいきませんでした。
どのようにしたら、自動調整をしてくれますでしょうか・・・。
下記にソースコードを設置しますので、教えていただけますと嬉しいです。
よろしくお願いいたします。
該当のソースコード
C#
1using Foundation; 2using System; 3using UIKit; 4using System.Collections.Generic; 5 6namespace SampleTableViewApp.iOS 7{ 8 public partial class MyTableViewController : UITableViewController 9 { 10 public MyTableViewController (IntPtr handle) : base (handle) 11 { 12 } 13 14 public override void ViewDidLoad() 15 { 16 base.ViewDidLoad(); 17 TableView.Source = new ListSource(); 18 TableView.ReloadData(); 19 //TableView.EstimatedRowHeight = 100; 20 //TableView.RowHeight = UITableViewAutomaticDimension; 21 } 22 23 public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath) 24 { 25 tableView.ReloadData(); 26 //if (cell.RespondsToSelector(new ObjCRuntime.Selector("setSeparatorInset:"))) cell.SeparatorInset = UIEdgeInsets.Zero; 27 //if (cell.RespondsToSelector(new ObjCRuntime.Selector("setLayoutMargins:"))) cell.LayoutMargins = UIEdgeInsets.Zero; 28 } 29 30 class ListSource : UITableViewSource 31 { 32 readonly List<string> _ar = new List<string> { "aaa", "bbb", "ccc", "ddd", "eee" }; 33 34 public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 35 { 36 var cell = tableView.DequeueReusableCell("MyCell"); 37 if (cell == null) 38 { 39 // セルの生成(最初に各セルを1回だけ生成する) 40 cell = new UITableViewCell(UITableViewCellStyle.Default, "MyCell"); 41 } 42 //tableView.ReloadData(); 43 //cell.TextLabel.Text = _ar[indexPath.Row]; 44 return cell; 45 } 46 47 public override nint RowsInSection(UITableView tableview, nint section) 48 { 49 //throw new NotImplementedException(); 50 return _ar.Count; 51 } 52 } 53 } 54}
試したこと
- TableView.ReloadData();
- TableView.EstimatedRowHeight = 100;
- Storyboardで、高さの設定
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/05 10:53
2018/02/05 11:12
2018/02/05 11:20