3秒后结束的UIRefreshControlRefreshing

时间:2016-04-28 12:12:51

标签: ios swift uitableview uirefreshcontrol

我有一个使用UITableView更新UIRefreshControl的功能。但我想在3秒后调用函数EndRefreshing

func updateMyTable(){

    tableView.reloadData()

    //refreshTable.endRefreshing()  
}

2 个答案:

答案 0 :(得分:5)

我在swift上知道的最好的延迟方法:

func dispatchDelay(delay:Double, closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
}

您的代码将是:

func updateMyTable(){
    tableView.reloadData()
    dispatchDelay(3.0) {
       self.refresh.endRefreshing()
    }
}

更新Swit 3:

func dispatchDelay(delay:Double, closure:@escaping ()->()) {
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay, execute: closure)
}

答案 1 :(得分:1)

尝试使用以下内容延迟一段时间后调用该方法:

<asp:TemplateField  ItemStyle-HorizontalAlign="Center" HeaderText="My Image">
<ItemTemplate>
<div id="imageDiv" runat="server" style="display: none">
</div>
</ItemTemplate>
</asp:TemplateField>


    protected void MyGridView_RowCreated(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            MyObjectType someData = (MyObjectType)e.Row.DataItem;
            if (null != someData)
            {
                HtmlContainerControl imageDiv = (HtmlContainerControl)e.Row.FindControl("imageDiv");
                imageDiv.InnerHtml = "<img id=\"img1\" runat=\"server\" src=\"" + "data:image/png;base64," + Convert.ToBase64String(someData.Pictures[0]) + "\" alt=\"Return\" width=\"180\" height=\"120\" style=\"padding:4px\" />";

            }

        }
    }

该方法将在3秒延迟后调用。因此,在更新表格的位置添加此行。

希望有所帮助......