iOS Question Tableview scroll event? Is it possible?

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Hi there!

I need to identify when my table view achieved the bottom elements.

When this happens I should be able to load more data into it. Is this possible in any way?

Thanks.
 
Last edited:

narek adonts

Well-Known Member
Licensed User
Longtime User
Hi there!

I need to identify when my table view achieved the bottom elements.

When this happens I should be able to load more data into it. Is this possible in any way?

Thanks.

I am using this code but I dont know if it suits to you as the TableView events will not work (itemselect,accessorybuttonclick,...)

B4X:
Dim YourTableview as TableView
Dim no as NativeObject=YourTableView
no.setField("delegate",me)

Sub sc_begin(OffsetX As Int, OffsetY As Int)

    'Begin Scrolling  

End Sub

Sub sc_ScrollChanged (OffsetX As Int, OffsetY As Int)

    'TableView is scrolling

End Sub

Sub sc_bottom

'Load More Data here

End Sub

#if OBJC

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

 
    CGPoint offset = scrollView.contentOffset;
    CGRect bounds = scrollView.bounds;
    CGSize size = scrollView.contentSize;
    UIEdgeInsets inset = scrollView.contentInset;
    float y = offset.y + bounds.size.height - inset.bottom;
    float h = size.height;

    float reload_distance = 10;
    if(y > h + reload_distance) {
        NSLog(@"load more rows");
        [self.bi raiseUIEvent:nil event:@"sc_bottom" params:@[]];
    }
 
    [self.bi raiseUIEvent:nil event:@"sc_scrollchanged::" params:@[@((float)scrollView.contentOffset.x),@((float)scrollView.contentOffset.y)]];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.bi raiseUIEvent:nil event:@"sc_begin::" params:@[@((float)scrollView.contentOffset.x),@((float)scrollView.contentOffset.y)]];

}

#end if
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User

Oh yeah!!!

It sounds a good approach! My only concern is how to handle the selected event!

Did you implement any event to handle the selection for one TableCell?

And also, how can I recover some values on B4i side, like I can do using TableCell.tag? Any thoughts?

Many thanks.
 
Last edited:
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User


I am using CustomView thats why I dont need this event.

You can try to add this objc code and TableView_selectionchanged event should work

B4X:
#If Objc

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

B4ITableView *t=self._tbl;
NSArray *arr=([t GetItems:indexPath.section]).object;
B4ITableCell* tc = [arr objectAtIndex:indexPath.row];

[self.bi raiseUIEvent:nil event:@"tbl_selectedchanged::" params:@[@((int)indexPath.section),(tc)]];


}

#end if

In this case your tableview is named tbl and is declared as global
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
In this case your tableview is named tbl and is declared as global
you can also create a wrapper with
B4X:
B4ITableView * t = [B4IObjectWrapper createWrapper:[B4ITableView new ] object:tableView];
then you don't have to use the global variable.

Jan
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User

Doing this all the context will be shared between B4i and the native controllers?

Thanks.
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
=D =D =D

You guys are rockstars!!! Works like a charm.

Just one more questions though!

The method "sc_bottom" is fired more than once. Any thoughts?

Thanks again.
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
=D =D =D

You guys are rockstars!!! Works like a charm.

Just one more questions though!

The method "sc_bottom" is fired more than once. Any thoughts?

Thanks again.
You can create a Boolean for example and when reloading new data set this Bollean to True and when finising the reload process set it to False. And for each sc_bottom event check if it is true or false. If it is true then Return
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…