iOS Tutorial TableView - Action (swipe) Buttons

Discussion in 'iOS Tutorials' started by Erel, Dec 6, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    TableView2 library extends TableView and adds support for action buttons.
    The reason for the new library is that TableView2 requires iOS 8+.
    You can download it here: http://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/page-2#post-385518

    upload_2015-12-6_16-1-24.png

    Action buttons can be added items with TableCell.AddActionButton.
    The buttons are revealed with a swipe.

    The ActionButtonClicked event is raised when the user clicks on one of the buttons.

    A complete example:
    Code:
    Sub Process_Globals
       
    Public App As Application
       
    Public NavControl As NavigationController
       
    Private Page1 As Page
       
    Private TableView1 As TableView
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.Title = 
    "Page 1"
       Page1.RootPanel.Color = 
    Colors.White
       NavControl.ShowPage(Page1)
       TableView1.Initialize(
    "TableView1"False)
       
    For i = 1 To 1000
         
    Dim tc As TableCell = TableView1.AddSingleLine($"Item #${i}"$)
         tc.AddActionButton(
    "Delete"Colors.Red)
         tc.AddActionButton(
    "Change Value"Colors.Green)
       
    Next
       Page1.RootPanel.AddView(TableView1, 
    00100%x100%y)
    End Sub

    Private Sub TableView1_ActionButtonClicked (SectionIndex As Int, Cell As TableCell, Text As String)
       
    Select Text
         
    Case "Delete"
           TableView1.BeginUpdates
           TableView1.RemoveCells(SectionIndex, TableView1.GetItems(SectionIndex).IndexOf(Cell), 
    1)
           TableView1.EndUpdates
         
    Case "Change Value"
           
    Dim s As AttributedString
           s.Initialize(
    "New Value"Font.DEFAULT_BOLD, Rnd(Colors.Black, Colors.White))
           Cell.Text = s
           Cell.Update
       
    End Select
    End Sub

    Private Sub Page1_Resize(Width As Int, Height As Int)
       TableView1.SetLayoutAnimated(
    0100100%x100%y)
    End Sub
     
    luke2012, ilan, imbault and 1 other person like this.
  2. narek adonts

    narek adonts Well-Known Member Licensed User

    Maybe using the opportunity of xreating new lib for TableView you could also add the wishes ))
    Animation for inserting, removing. And custom accessory views.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Note that this is not a new library. The new version is only because of the iOS 8 requirement. Custom accessory views can be easily implemented with custom views.

    Inserting and removing items actions are animated. I guess that you mean that you want to explicitly choose the animated instead of the automatic mode.
     
    valentino s likes this.
  4. narek adonts

    narek adonts Well-Known Member Licensed User

    Yes, correct.

    Regaring the custom accesoryviews it is much easer to add just one more function (uitableviewCell.accessoryView) then entirely creating a custom cell.
    Anyway thank you).
    It will be much beter if you could return the tableCell as native UitableViewCell to be able to use it with native object
     
  5. narek adonts

    narek adonts Well-Known Member Licensed User

    Found a solution for the Accesory Views with Native Objects ))

    Code:
    Dim noTbl As NativeObject=MytableView
        
    Dim ip As NativeObject
        ip=ip.Initialize(
    "NSIndexPath").RunMethod("indexPathForRow:inSection:",Array(Row,Section))
        
    Dim cell As NativeObject=noTbl.RunMethod("cellForRowAtIndexPath:",Array(ip))
       
        
    Dim V As View
       
        cell.SetField(
    "accessoryView",V)
     
  6. MikeH

    MikeH Well-Known Member Licensed User

    Is it possible to have an image instead of text in the swipe button?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    No. Only text is supported.
     
  8. ilan

    ilan Expert Licensed User

    hi

    i have a question please

    when i intialize the tableview and create the items and then add the table to a panel everything is fine but then when i want to clear all items and load again new items to the tableview i get blank items. i solved it by intializing again the tableview but i think that its not the right way.

    what could be a reason for that behavior? thanx
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
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