如何实时重新加载UITableView



UITableView导航栏右侧有一个同步按钮的控制器。当用户首次进入此屏幕时,表为空。当我单击同步按钮时,我想:

  • 调用我的函数以获取新数据

  • 立即在视图中重新加载数据(不必返回或转到另一个视图即可刷新)

现在,桌子

似乎什么都没有发生,除非我回到屏幕,然后回来。这是我的代码:

public override viewdidload(){
    base.viewdidload();
    MyTable.Source = new MyListSource (items, this);
    this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Action, syncMe), true);
}
public async void syncMe(){
    await getData();
    MyTable.ReloadData();
}

试试这个:

public override viewdidload()
{
    base.viewdidload();
    MyTable.Source = new MyListSource (items, this);
    this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Action, syncMe), true);
}
public async void syncMe()
{
    items = await getData();
    MyTable.Source = new MyListSource (items, this);
    MyTable.ReloadData();
}

最新更新