在 Xamarin Forms for iOS 中,我尝试在 ListView 出现之前为其设置滚动位置。当 ListView 显示时,触发可见滚动到底部。有什么想法,如何在 ListView 出现之前设置滚动位置?
[assembly: ExportRenderer(typeof(MyListView), typeof(NativeiOSListViewRenderer))]
namespace MyApp.iOS.Renderers
{
public class NativeiOSListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var element = e.NewElement as MyListView;
if (element.ItemsSource is IList items && items.Count > 0)
{
var tableView = Control as UITableView;
var indexPath = NSIndexPath.FromItemSection(itemIndexitems.Count - 1, 0);
tableView.ScrollToRow(indexPath, UITableViewScrollPosition.Bottom, false);
}
}
}
}
}