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

Code:
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


Code:
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:
Hi,
based on narek's code, I have created a module, which allows you to use a LoadingIndicatorView as RefreshControl.

Jan
 

Attachments

Last edited:
Based on Narek's code, here's how add the RefreshControl to a WebView:

Code:
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
 
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.
 
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?
 
Back
Top