alekseyn / EasyTableView

Horizontal and vertical scrolling table views for iOS
BSD 3-Clause "New" or "Revised" License
584 stars 157 forks source link

Problem with bouncing #6

Closed SlavaBushtruk closed 12 years ago

SlavaBushtruk commented 13 years ago

If you embed EasyTable as a subview to a UIScrollView the left bouncing is broken. So if you want to build Pulse like UI it's not a good idea to use this component.

thiagoperes commented 13 years ago

Yes =/ any ideas?

SlavaBushtruk commented 13 years ago

No, chance. I've tried everything possible. As Apple said, DON"T put UITableView to UIScrollView because their gestures conflicts.

thiagoperes commented 13 years ago

So you're suggesting pulse used a different approach? Like a custom UIScrollView with memory management?

SlavaBushtruk commented 13 years ago

Yes, obsolutely. We've published similar control: https://github.com/Kastet/APCarouselView

borut-t commented 12 years ago

Pulse uses tableView inside another tableView: http://itunes.apple.com/de/podcast/10-hacks-to-go-from-idea-to/id395605774?i=88960658

SlavaBushtruk commented 12 years ago

Thanks. I'll watch this.

BrandonCopley commented 12 years ago

Here's the solution - Wrap the UITableView in a UIScrollView : ) - Pretty simple and works great for me. http://blog.brandoncopley.com/?p=110 - this is for a tableview within a tableview solution.

I first tried touchesbegan, etc. and that worked but touchescancelled got called on vertical scrolling so it just acted odd, you would scroll left and right and then BAM touches cancelled when you moved 1 px vertical. This works beautifully though.

BrandonCopley commented 12 years ago

I have pulse like UI using this and I can assure you it works great...I can send a video of it in action as well. Just wrap that uitableview in a scrollview before embedding it in another uitableview.

BrandonCopley commented 12 years ago

Here is the code I swapped...

SlavaBushtruk commented 12 years ago

Please send a video. Apple recommends not to use UITableView inside UIScrollVIew.

BrandonCopley commented 12 years ago

http://www.youtube.com/watch?v=r0BUynKrmdA&feature=youtube_gdata_player

BrandonCopley commented 12 years ago

Of course you "shouldn't" place a UITableView within a UIScrollView because the UIScrollView overwrites some touch events that disable horizontal scrolling, however what happens here is that by making the UIScrollView frame and contentsize identical to the UITableView nothing is overwritten OTHER than disabling the UITableView ignoring horizontal touches that disable horizontal bouncing. This lets us allow for horizontal touches and on our own vertical is already disabled.

borut-t commented 12 years ago

@BrandonCopley: How did you make your Pulse-like tableView vertical scrolling so smooth (video)? I have a huge problem here cos I reload horizontalTableView every time it's shown. Otherwise the content is not right and is reused from other cells.

Do you have any suggestion or how did you do it?

BrandonCopley commented 12 years ago

When I set the data I remove the datasource objects and internally I have a NSDictionary containing the datasources and just set the datasource to the correct datasource for that view. This is a common problem even for Asynchronous image loading - make sure that every object in your cell is set to either the correct object or nil.

DataSource * oldDataSource = (DataSource*)[_dataSourceCache valueForKey:easyTableViewCell.comicName]; easyTableViewCell.dataSource = nil; easyTableViewCell.dataSource = [oldDataSource copy];

easyTableViewCell.easyTableView.items = nil; easyTableViewCell.easyTableView.items = easyTableViewCell.dataSource.items;

borut-t commented 12 years ago

I am keeping datasource in and object "self.categoriesWithNewsData". In vertical tableView method cellForRowAtIndexPath I do this: [cell setData:[self.categoriesWithNewsData objectForKey:indexPath.row]];, but not in if (cell == nil) condition.

In horizontal tableView class I do this: self.newsRecords = data; //data that was passed from vertical tableView [self.horizontalTableView reloadData];

I don't know exactly how to implement this. Can you show me your code?

Thanks!

BrandonCopley commented 12 years ago

On cell == nil make sure you remove the data source. I "clear" the cell everytime set data is called.

On Nov 18, 2011, at 1:56 AM, "Borut Tomažin" reply@reply.github.com wrote:

I am keeping datasource in and object "self.categoriesWithNewsData". In vertical tableView method cellForRowAtIndexPath I do this: [cell setData:[self.categoriesWithNewsData objectForKey:indexPath.row]];, but not in if (cell == nil) condition.

In horizontal tableView class I do this: self.newsRecords = data; //data that was passed from vertical tableView [self.horizontalTableView reloadData];

I don't know exactly how to implement this. Can you show me your code?

Thanks!


Reply to this email directly or view it on GitHub: https://github.com/alekseyn/EasyTableView/issues/6#issuecomment-2786711

borut-t commented 12 years ago

It's still clunky. On iPad I have 5 vertical visible rows and each row has four visible rows. Thats 20 cells to draw on scroll. Each cell's contentView has inside UIImageView and UILabel as subview which has alpha set.

I am still trying to improve scrolling performance. Any suggestions?

BrandonCopley commented 12 years ago

Ahh yes, make sure very little drawing is occuring in your UITableViewCell. Drawing is expensive. Don't redraw views, force your EasyTableView cell view to be as reusable as possible. Drawing views in a cell is very expensive. For instance in my app I have the tableviewcell, but no "drawing" of views takes place, only image swaps. This is drawing, but much less expensive then redrawing the image completely. Spend some time studying Apple's videos on UITableView's and how UITableViewCells are reused. Their reuse is very very important to a good app.

Time is a huge factor here in a scrolling view and reuse saves a lot of processing. For fun I once built a tableview without reuse and it had 100 cells and took 1 second to load on startup, built the same with a reusable cell and I had 1 base cell and it got reused 100 times and loads instantly and works great. UITableViewCell reuse is very important.

2011/11/18 Borut Tomažin < reply@reply.github.com

It's still clunky. On iPad I have 5 vertical visible rows and each row has four visible rows. Thats 20 cells to draw on scroll. Each cell's contentView has inside UIImageView and UILabel as subview which has alpha set.

I am still trying to improve scrolling performance. Any suggestions?


Reply to this email directly or view it on GitHub: https://github.com/alekseyn/EasyTableView/issues/6#issuecomment-2788987

SlavaBushtruk commented 12 years ago

I like your video. Seems it works really great. It's a pity you didn't answer months ago. We already implemented own different custom controls for this purpose.

Anyway a good sample would be good to learn before try to embed in big project. Thanks.

BrandonCopley commented 12 years ago

I apologize, I just figured this out as I posted it :). I'd been staring at the problem for a few hours and had built something using touches began, etc. but wasn't satisfied because it felt wrong so I thought through what methods worked and what was being disabled and figured that wrapping it in the uiscrollview would override the methods disabling horizontal scroll.

On Nov 20, 2011, at 11:01 AM, Slava Bushtruk reply@reply.github.com wrote:

I like your video. Seems it works really great. It's a pity you didn't answer months ago. We already implemented to own different custom controls for this purpose.

Anyway a good sample would be good to learn before try to embed in big project. Thanks.


Reply to this email directly or view it on GitHub: https://github.com/alekseyn/EasyTableView/issues/6#issuecomment-2805029

thiagoperes commented 12 years ago

@BrandonCopley great solution.

Not only the scroll view thing, but I also like how you managed to get such a great performance.

We should make an EasyTableView 2.0

SlavaBushtruk commented 12 years ago

OK. Let's share some additional code and we try to help. If it's possible. Tomorrow we want to try to embed the component instead our own because standard UITableView animation for insert/remove. Any more advises or code sample?

SlavaBushtruk commented 12 years ago

@BrandonCopley, I have first prototype with some of your comments and it works perfect. Scrolling is just awesomely smooth. I'd post an update but it's too far from original code now. Thanks.

BrandonCopley commented 12 years ago

Awesome, I think in the code I posted I wrapped both horizontal and vertical table views in the UIScrollView and I don't know if you want to wrap both in a UIScrollView.

Also, another tweak I made that makes sense for my use, but I think is practical is dynamic cell heights set by a delegate.

ex:

- (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath { if ([delegate respondsToSelector:@selector(easyTableView:heightForRowAtIndexPath:)]) { return [delegate easyTableView:self heightForRowAtIndexPath:indexPath]; } return _cellWidthOrHeight; }