iOS Code Snippet RefreshControl for TableView and ScrollView

Based on http://stackoverflow.com/questions/12497940/uirefreshcontrol-without-uitableviewcontroller

Add a UIRefreshControl to your TableView or ScrollView

TABLEVIEW

B4X:
Public Sub AddRefresh (TableView As TableView)
Dim nome as NativeObject=Me 
nome.RunMethod("AddRefresh:",Array(TableView))
End Sub

Sub refreshing(RefreshControl As Object)
 
      ' DO YOUR REFRESHING JOB

    Dim no As NativeObject=RefreshControl
    no.RunMethod("endRefreshing",Null)  ' END REFRESHING
End Sub

#IF OBJC

-(void)AddRefresh: (UITableView*)tbl {
    UITableViewController *tableViewController = [[UITableViewController alloc] init];
    tableViewController.tableView = tbl;
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
    tableViewController.refreshControl = refreshControl;
}

- (void)refresh:(id)sender {

    UIRefreshControl *refreshControl=sender;
    [self.bi raiseEvent:nil event:@"refreshing:" params:@[(refreshControl)]];
 
}


#END IF


SCROLLVIEW


B4X:
Public Sub AddRefresh (ScrollView as ScrollView)
Dim nome as NativeObject=Me
nome.RunMethod("AddRefresh:",Array(ScrollView))
End Sub

Sub refreshing(RefreshControl As Object)

      ' DO YOUR REFRESHING JOB

    Dim no As NativeObject=RefreshControl
    no.RunMethod("endRefreshing",Null)  ' END REFRESHING
End Sub

#IF OBJC

-(void)AddRefresh: (UIScrollView*)scrollView {
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [scrollView addSubview:refreshControl];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

}

- (void)refresh:(id)sender {
    UIRefreshControl *refreshControl=sender;
    [self.bi raiseEvent:nil event:@"refreshing:" params:@[(refreshControl)]];

}

#END IF
 
Last edited:

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
based on narek's code, I have created a module, which allows you to use a LoadingIndicatorView as RefreshControl.

Jan
 

Attachments

  • RefreshControl.bas
    2.2 KB · Views: 686
Last edited:

dbalman

Member
Licensed User
Longtime User
Based on Narek's code, here's how add the RefreshControl to a WebView:

B4X:
Public Sub AddRefresh (WebView As WebView)
   Dim no As NativeObject = Me
   no.RunMethod("AddRefresh:",Array(WebView))
End Sub

Sub refreshing(RefreshControl As Object)
  
  ' DO YOUR REFRESHING JOB

  Dim no As NativeObject = RefreshControl
  no.RunMethod("endRefreshing", Null)  ' END REFRESHING
End Sub

#IF OBJC

-(void)AddRefresh: (UIWebView*)webView {
  UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
  [webView.scrollView addSubview:refreshControl];
  [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

}

- (void)refresh:(id)sender {
  UIRefreshControl *refreshControl=sender;
  [self.bi raiseEvent:nil event:@"refreshing:" params:@[(refreshControl)]];

}

#END IF
 

hongbii khaw

Member
Licensed User
Longtime User
Hi,
First of all, thanks for the code.
I found that it's unable to refresh the table view if the table view's height greater than screen's size.
Is that any solution for this?
Thank you.
 

narek adonts

Well-Known Member
Licensed User
Longtime User
Hi,
First of all, thanks for the code.
I found that it's unable to refresh the table view if the table view's height greater than screen's size.
Is that any solution for this?
Thank you.
I dont know but why the tableview height is bigger the the screens height?
 
Top