Menu

Enhancement for TDPFUITableView( Scroll up/down and check on top/bottom )

2013-08-19
2013-08-19
  • heroes3lover

    heroes3lover - 2013-08-19

    Hi, I got problem with loading data to the TDPFUITableView.
    I need to load a fixed amount of data to the TDPFUITableView, when it scroll up or down,
    Load another. I checked the source and can't find a good way to do this( am I wrong? ).
    so I wrote my own code there, hopefully the next version can support similar requirement
    and help other guys.

    Thanks,
    Hao

    type

    TDPFTableViewScrollBegin = procedure( Sender: TObject) of object;
    TDPFTableViewScrollend = procedure( Sender: TObject; sp, tp : CGPoint) of object;

    TDPFUITableView = class( TDPFiOSBaseControl )
    ///***///
    private
    {$IFDEF IOS}
    FOnScrollBegin : TDPFTableViewScrollBegin;
    FOnScrollEnd : TDPFTableViewScrollend;
    {$ENDIF}
    public
    {$IFDEF IOS}
    CurOffSet : CGPoint;
    property OnScrollBegin : TDPFTableViewScrollBegin read FOnScrollBegin write FOnScrollBegin;
    property OnScrollEnd : TDPFTableViewScrollend read FOnScrollEnd write FOnScrollEnd;
    function BOF :Boolean;
    function EOF : Boolean;
    {$ENDIF}
    ///******///
    end;

    constructor TDPFUITableView.Create( AOwner: TComponent );
    begin
    //**//
    {$IFDEF IOS}
    FOnScrollBegin := nil;
    FOnScrollEnd := nil;
    CurOffSet.x := 0;
    CurOffSet.y := 0;
    {$ENDIF}
    end;

    {$IFDEF IOS}
    function TDPFUITableView.EOF : Boolean;
    var
    height : CGFloat;
    contentYoffset : CGFloat;
    distanceFromBottom : CGFloat;
    begin
    Result := False;
    height := FUITableView.frame.size.height;
    contentYoffset := FUITableView.contentOffset.y;
    distanceFromBottom := FUITableView.contentSize.height - contentYoffset;
    if(distanceFromBottom <= height)then
    Result := True;
    end;

    function TDPFUITableView.BOF : Boolean;
    begin
    Result :=( CurOffSet.y<=0 );
    end;
    {$ENDIF}

    //**TTableViewDelegate**//
    procedure TTableViewDelegate.scrollViewWillBeginDragging( scrollView: UIScrollView );
    begin
    //
    **//
    FDPFUITableView.CurOffSet := scrollView.contentOffset;
    if( Assigned( FDPFUITableView.OnScrollBegin ))then
    FDPFUITableView.OnScrollBegin( Self );
    //
    **//
    end;

    // ------------------------------------------------------------------------------
    procedure TTableViewDelegate.scrollViewWillEndDragging( scrollView: UIScrollView; withVelocity: CGPoint; targetContentOffset: CGPoint );
    begin
    //****//
    if( Assigned( FDPFUITableView.OnScrollEnd))then
    FDPFUITableView.OnScrollEnd( Self, FDPFUITableView.CurOffSet, scrollView.contentOffset );
    FDPFUITableView.CurOffSet := scrollView.contentOffset;
    end;

    //sample to use the function above

    vwItems: TDPFUITableView;

    vwItems.OnScrollEnd := ScrollEnd;

    procedure TfrmItemSearch.ScrollEnd( Sender : TObject; sp, tp : CGPoint );
    begin
    if( sp.y>tp.y )then//scroll up
    begin
    if( vwItems.BOF )then
    begin
    //do something
    end;
    end
    else//scroll down
    begin
    if( vwItems.Eof )then
    begin
    //do something
    end;
    end;
    end;

     
  • heroes3lover

    heroes3lover - 2013-08-19

    sorry about the formatting, don't know how to do it.

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-19

    Hi, heroes3lover

    Both OnScrollBegin, OnScrollEnd events will be added in the next release,

    thank you for feedback

    regards

     
  • heroes3lover

    heroes3lover - 2013-08-19

    Hi Babak,

    Is there any better way to know the tableview already scroll up to the begin or down to the end? I saw lots of discussion with XCode then I translate one to Delphi XE4 as above. how to do that without my BOF/EOF code?

    Thanks,
    Hao

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.