iOS Code Snippet RefreshControl for TableView and ScrollView

Discussion in 'iOS Code Snippets' started by narek adonts, Sep 28, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    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: Mar 26, 2016
  2. narek adonts

    narek adonts Well-Known Member Licensed User

    UPDATED - Add Refresh Control for also for ScrollView

    See 1st post.

    Narek
     
    Erel likes this.
  3. JanPRO

    JanPRO Well-Known Member Licensed User

    Hi,
    based on narek's code, I have created a module, which allows you to use a LoadingIndicatorView as RefreshControl.

    Jan
     

    Attached Files:

    Last edited: Jul 25, 2016
    dbalman, Erel and narek adonts like this.
  4. dbalman

    dbalman Member Licensed User

    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
     
    Erel and JanPRO like this.
  5. hongbii khaw

    hongbii khaw Member Licensed 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.
     
  6. narek adonts

    narek adonts Well-Known Member Licensed User

    I dont know but why the tableview height is bigger the the screens height?
     
Loading...