【发布时间】:2013-12-17 17:28:52
【问题描述】:
我正在使用 Monotouch.Dialog 并且需要重新定位一些 EntryElements - 当它们在一个部分内时它们似乎会漂移。
我将框架设置为frame.X = frame.X - 5; 以解决此问题。但是,如果单元格离开屏幕,然后在框架上向后滚动,则似乎已重置并且 UI 看起来不合时宜。
我能做些什么来确保框架永远不会重置或至少恢复到应有的状态?
这是代码 - 这是使用 Monotouch.Dialog 的 MvvmCross 端口,因此 GetCell 现在是 GetCellImpl - 它的工作方式几乎相同 - 在它的基类 (EntryElement) 中调用 dequeuereusablecell,我正在修改无论如何,在那之后的单元格......所以不应该工作吗?:
public class MyEntryElement : EntryElement, IElementSizing
{
public bool Disabled {
get;
set;
}
public MyClaimEntryElement()
: base()
{
}
public MyEntryElement(string caption)
: base(caption)
{
}
public MyEntryElement(string caption, string placeholder)
: base(caption, placeholder)
{
}
public MyEntryElement(string caption, string placeholder, string value)
: base(caption, placeholder, value)
{
}
public MyEntryElement(string caption, string placeholder, string value, bool isPassword)
: base(caption, placeholder, value, isPassword)
{
}
protected override UITableViewCell GetCellImpl(UITableView tv)
{
var cell = base.GetCellImpl(tv);
cell.BackgroundColor = UIColor.Clear;
UITextField uiTextField;
if (cell.ContentView.Subviews.Length == 1)
{
uiTextField = ((UITextField)cell.ContentView.Subviews[0]);
}
else
{
uiTextField = ((UITextField)cell.ContentView.Subviews[1]);
}
if (cell.ContentView.Subviews.Length == 2) {
var labelField = ((UILabel)cell.ContentView.Subviews [0]);
labelField.TextColor = UIColor.White;
}
uiTextField.Enabled = Disabled;
uiTextField.TextColor = UIColor.Black;
uiTextField.Background = UiHelper.Text_Bubble;
uiTextField.Enabled = !Disabled;
var frame = uiTextField.Frame;
frame.X = frame.X - 5;
frame.Height = frame.Height + 10;
uiTextField.Frame = frame;
return cell;
}
private const float CellHeight = 40; //standard height. You can make it bigger or smaller, tho smaller means fingers miss easier.
public float GetHeight(UITableView tableView, NSIndexPath indexPath)
{
return CellHeight;
}
}
【问题讨论】:
-
你需要展示一些代码。单元格被重复使用(即缓存),因此任何离开屏幕的单元格可能与您返回的单元格不同。 IOW 在哪里设置框架很重要。
-
我通过将 X 设置为静态值而不是计算来解决此问题
标签: ios uitableview xamarin.ios xamarin monotouch.dialog