iOS Tutorial Add UIRefreshControl To CustomListView

Discussion in 'iOS Tutorials' started by Brandsum, May 31, 2019.

  1. Brandsum

    Brandsum Active Member Licensed User

    Original Tutorial by @narek adonts

    Create a standard class module (Let assume the name of the class is UIRefreshControl),
    Code:
    Sub Class_Globals
        
    Private CSB As CSBuilder
        
    Private cb As Object
        
    Private en As String
        
    Private RefreshControl As NativeObject
    End Sub

    Public Sub Initialize(callback As Object, EventName As String, sv As ScrollView)
        cb = callback
        en=EventName
        
    Dim no As NativeObject=Me
        RefreshControl = no.RunMethod(
    "AddRefresh:",Array(sv))
        RefreshControl.SetField(
    "attributedTitle",CSB.Initialize.Append("Pull to refresh").PopAll) 'You can add AttributedString
    End Sub

    Public Sub EndRefreshing
        RefreshControl.RunMethod(
    "endRefreshing",Null)
        RefreshControl.SetField(
    "attributedTitle",CSB.Initialize.Append("Pull to refresh").PopAll) 'You can add AttributedString
    End Sub

    Private Sub RC_Refresh(RC As Object)
        RefreshControl.SetField(
    "attributedTitle",CSB.Initialize.Append("Refreshing...").PopAll) 'You can add AttributedString
        CallSub(cb, en&"_PullRefresh")
    End Sub

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

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

    }
    #end if
    Now you can use this class to add refresh control to any CLV of any page you want. like this,
    Code:
    'Code module

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public MainPage As Page
        
    Private MainPageScroll As CustomListView
        
    Private MainRC As UIRefreshControl
    End Sub

    Public Sub ShowModule
        MainPage.Initialize(
    "MainPage")
        Main.NavControl.ShowPage(MainPage)
        MainPage.RootPanel.LoadLayout(
    "layout1")

        MainRC.Initialize(Me,
    "MainPageScroll",MainPageScroll.sv) 'add refresh control to CLV scrollview
    End Sub

    Sub MainPageScroll_PullRefresh
        Sleep(
    3000'do whatever you want
        MainRC.EndRefreshing
    End Sub
    Happy Coding :)
     
    Last edited: May 31, 2019
    Sasuke Sama likes this.
  2. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    Man your tutorials are awesome always what im looking for
     
    Brandsum likes this.
  3. Brandsum

    Brandsum Active Member Licensed User

    Thank you. :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice