Я создал один table view
, который имеет 6 ярлыков и 2 кнопки. Я использую автозапуск. И я получаю данные с сервера.Динамическая высота ячеек в представлении таблицы Не работает
ViewController.cs
public partial class CaseHistoryController : UIViewController
{
private List<CaseSearchItem> caseSearchItems;
CaseHistorySourceClass caseSearchSourceclass;
public CaseHistoryController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.Title = "Case History";
View.BackgroundColor = UIColor.Clear.FromHexString("#DDDDDD", 1.0f);
var task = GetCaseHistoryData();
}
private async Task GetCaseHistoryData()
{
caseSearchItems = await CaseHistoryServices.GetListCaseHistory();
caseSearchSourceclass = new CaseHistorySourceClass(caseSearchItems);
CaseHistorySourceClass.RowClicked += (sender, e) =>
{
var webController = Storyboard.InstantiateViewController("UserInfoViewController") as UserInfoViewController;
webController.caseSearchItem = (CaseSearchItem)sender;
NavigationController.PushViewController(webController, true);
};
caseHistoryTableView.Source = caseSearchSourceclass;
caseHistoryTableView.BackgroundColor = UIColor.Clear.FromHexString("#DDDDDD", 1.0f);
caseHistoryTableView.SectionHeaderHeight = 0.0f;
caseHistoryTableView.SectionFooterHeight = 5.0f;
caseHistoryTableView.ContentInset = new UIEdgeInsets(0, 0, 10.0f, 0);
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
caseHistoryTableView.ReloadData();
caseHistoryTableView.RowHeight = UITableView.AutomaticDimension;
caseHistoryTableView.EstimatedRowHeight = 145.0f;
}
public class CaseHistorySourceClass : UITableViewSource
{
private List<CaseSearchItem> caseSearchItems;
public CaseSearchItem caseSearchItem;
public static event EventHandler RowClicked;
public CaseHistorySourceClass(List<CaseSearchItem> caseSearchItems)
{
this.caseSearchItems = caseSearchItems;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
CaseHistoryTableCell cell = tableView.DequeueReusableCell(CaseHistoryTableCell.Key) as CaseHistoryTableCell ?? CaseHistoryTableCell.Create();
var item = caseSearchItems[indexPath.Row];
cell.BindData(item.Organization, item.Address, item.Doctor, item.UserName);
cell.Layer.MasksToBounds = false;
cell.Layer.CornerRadius = 10.0f;
cell.BackgroundColor = UIColor.White;
return cell;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
caseSearchItem = caseSearchItems[indexPath.Row];
tableView.DeselectRow(indexPath, true);
if (RowClicked != null)
RowClicked(caseSearchItem, EventArgs.Empty);
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return caseSearchItems.Count;
}
}
}
TableViewCell.cs
public partial class CaseHistoryTableCell : UITableViewCell
{
public static readonly NSString Key = new NSString("CaseHistoryTableCell");
public static readonly UINib Nib;
static CaseHistoryTableCell()
{
Nib = UINib.FromName("CaseHistoryTableCell", NSBundle.MainBundle);
}
public CaseHistoryTableCell(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public static CaseHistoryTableCell Create()
{
return (CaseHistoryTableCell)Nib.Instantiate(null, null)[0];
}
public void BindData(string hospitalLabel, string addressLabel, string drLabel, string patientLabel)
{
this.lbl_hospitalName.Text = hospitalLabel;
this.lbl_address.Text = addressLabel;
this.lbl_drName.Text = drLabel;
this.lbl_patientName.Text = patientLabel;
this.lbl_address.TextColor = UIColor.Clear.FromHexString("#000000", 0.54f);
this.lbl_patientName.TextColor = UIColor.Clear.FromHexString("#000000", 0.54f);
this.lbl_hospitalName.TextColor = UIColor.Clear.FromHexString("#000000", 0.87f);
this.lbl_drName.TextColor = UIColor.Clear.FromHexString("#000000", 0.87f);
this.btn_createAppointment.SetTitleColor(UIColor.Clear.FromHexString("#0072BA", 1.0f), UIControlState.Normal);
this.btn_viewDetail.SetTitleColor(UIColor.Clear.FromHexString("#0072BA", 1.0f), UIControlState.Normal);
}
public override CGRect Frame
{
get
{
return base.Frame;
}
set
{
value.Y += 4;
value.Height -= 2 * 4;
base.Frame = value;
}
}
}
То, что я хочу это:
Я хочу, чтобы все высота ячейки динамической. Но каждый раз вторая ячейка не принимает корректировки.
То, что я пробовал:
1.)
В ViewDidAppear
, я установил следующее:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
caseHistoryTableView.ReloadData();
caseHistoryTableView.RowHeight = UITableView.AutomaticDimension;
caseHistoryTableView.EstimatedRowHeight = 145.0f;
}
2.)
В GetCell
метод, I добавить клеткам таким образом:
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
CaseHistoryTableCell cell = tableView.DequeueReusableCell(CaseHistoryTableCell.Key) as CaseHistoryTableCell ?? CaseHistoryTableCell.Create();
var item = caseSearchItems[indexPath.Row];
cell.BindData(item.Organization, item.Address, item.Doctor, item.UserName);
cell.Layer.MasksToBounds = false;
cell.Layer.CornerRadius = 10.0f;
cell.BackgroundColor = UIColor.White;
cell.SetNeedsLayout();
cell.LayoutIfNeeded();
return cell;
}
Но я все еще получаю ниже выхода:
Вторая ячейка не принимает автоматическую высоту.
Метка 1 ограничение: (больница этикетки)
Этикетка 2 constaint: (Адрес этикетки)
все это управляемо 'autolayout' и' tableviewdelegates' –
@TinuDahiya, как я уже говорил в своем вопросе, я использую 'autoLayout', но это не работа, снова смотрите вопрос. – Ironman
Изменение отношения высоты надписи от 'equalto (=)' to 'morethatequalto (> =)'. И я уже читал ваши вопросы, должно быть проблема в любом ограничении. –