ios - Making UIScrollView scroll smoothly - ios

In my iPad application, i've a scroll view that lists images of 20 video albums. The list of 20 images will be sent by server.
Now when the user reaches end of scroll view, i've to send a request to get next 10 videos details.
After fetching the data, i want to add them to the scroll view at the end. But I want to delete the 10 videos at the beginning. So that at a time scroll view will show only 20 video details all the time.
When user scrolls again to the end, i'll send request to server, get next 10 video details and add them to the scroll view, remove 10 beginning video details from scroll view...... and similarly when user scrolls to the beginning i'll fetch 10 previous videos and repeat the same.
Here i want to make sure the scrolling must be smooth and don't want to have flickers in scroll view. can some one suggest to have better scroll view coding to achieve my requirements please?

If your code contains scroll.pagingEnabled = YES; Then please remove this part of code.
It will surely work.

The real problem here will be in setting up cell recycling. It's not that hard to do, I have a couple examples of which you can look at, one being here. You'll need to make some changes to that code of course, it is set up in "pages" — Only one view on screen at any one time, and I don't think that's what you want.
Aside from that...
Your critical part here will be in designing your data source in a way that allows removing of old items, and adding new items, without skipping items.
For instance, the way I might approach this is to render the "last" item in your scroll view, the same as you want the first item in the scrollview to be. When the user gets to the last item, set your content offset to the start of the scrollview without animation (haven't actually tried this, so there may be a jolt that you don't want, test it and see). This will give the appearance of endless scrolling. Your data source would simply overwrite old indexes when adding new items, instead of adding to the end of an array for instance.

If you are presenting then in the form of a grid view, I suggest you take a look at AQGridView. That grid view supports cell queueing and dequeueing, which does exactly what you describe.
You can also use the delegate method scrollViewDidScroll: to determine if you're at the bottom of the scrollview and trigger the download of the next set of albums.

Related

How to recreate this iOS application view and animations?

I am new to iOS development and unable to identify how Google/YouTube built this view in the YouTubeTV app. Is this built using an UITableView?
Essentially, the top row is selectable (Pre-animation). As you scroll up, the top row gets pushed up and out of view (Mid-animation), while the second row fades and grows into, and replaces, the top row). I've included screenshots of the animation in-progress. Thanks for the info and assistance.
This would be done with a UITableView or a UICollectionView. What you would do is enable paging on the Table/Collection view, so that it only ever displays entire cells in the visible area of the view. You can then manipulate the height use the heightForCellAtIndexPath: function - as an example of how it could be done on a tableview.
There is actually a really good example on github - typically we try to give more full answers on SO, but in this case, this could be relevant to you just starting out. Not affiliated in anyway, but it's a really good example.
https://github.com/aslanyanhaik/youtube-iOS

Create a listing inside of a ScrollView

I am writing a Swift app, and on my main screen I have a long scrollview with several regions of content in it (upcoming events, announcements, and then featured products, and finally some basic info). So it's this really long scroll, and you can swipe down to the bottom.
So visualize 4 boxes, if you will, stacked vertically.
The 3rd box shows featured products. This can be anywhere from 1 to 30 items, depending upon any filters the user has in their settings.
My first try was using a UITableView for region#3 inside of this parent scrollview, but the problem is it only shows the first few items/rows and then the rest you scroll inside the table (which is the default/natural behavior of a table, right?). Unfortunately, the requirement I have is that the inner table can't scroll - it needs to display everything at once and you have to scroll (in the main UIScrollView) to get to the bottom (not scroll inside the inner uitableview scroll). Also, everyone seems to say don't use UITableView inside of a scroll.
So how do I create some sort of list where I create one template (like how you would in a xib/tablecell, and then assign a data source to it, and then repeat down without scrolling? Should I use a tableview after all, and just make the height of it very high and turn scrolling off?
Do I somehow instantiate xibs in a for loop and assign them dynamically to some view?
Thanks so much!
Sounds like you want a Table View with Grouped style. That would make it fairly easy to keep your "4 boxes" segregated, and your "3rd box" would simply be 1 to 30 rows in that section.
On note: you don't want to have a "very tall" table view - or any other type of view, for that matter. You want to allow iOS to manage memory for you, and to load and display only those parts of your content that is visible at any one time.
In other words, use a table view like its designed to be used :)

Best practice to have multiple tableviews in a single view controller

This question maybe already asked in stackoverflow. But, I did not get any clear idea to my scenario.
I have a viewcontroller (Say, MyViewController).
I have a scrollview(Say, MyScrollView) and I have N number of views (Say MyView1, MyView2, ...) in it.
Those views can be scrolled horizontally. Refer the below image for more clarification.
This image was taken from here.
So, the red area is the scroll view that holds multiple views which are yellow color.
Scenario:
I want to call API's for each view, when the API calling and parsing data occurs, I need to show some loading activity indicator in the views. After successful parsing, I need to update corresponding view with UITableView.
Questions:
In my case, the number of views may vary from 3 to 6. Should I maintain 6 separate UITableViews and UIActivityIndicator's?
I tried with three pointers like left, middle & right to hold reference of tableview and activity indicator. But the problem is, before the first three pages are loading, if the user goes to the fourth view, this system will collapse with so many conditions.
Suggestions needed. Confused!!
I think you have to use UIPageViewController with UITableView. it will solve your problem.

is it possible to use something like "reloadData" between 2 scroll views in iOS to keep the data loaded efficiently?

I have 2 scroll views. When click one of the buttons in the first Scroll view, some images related to this button will be retrieves from a plist and loaded into the second Scroll view.Is it possible to use something like "reloadData" between the 2 scroll views in iOS to keep the data loaded efficiently? Customers may click the buttons in the first Scroll view frequently, so we have to consider its efficiency and low system cost. Some sample code is appreciated. thanks!
you just simply make two arrays that hold the data of both scrollviews and make a method that empty the scrollview and add all the data again into (both)scrollviews and if you want to delete any element or data then you delete from scrollview as well as delete from array that hold the data of that scrollview then you just call that function and your scrollview is reloaded :-)

UITableView keep the scroll at the correct position while updating NSFetchedResultsController

I am developing an iOS application that mainly use a UITableView.
It retrieves pages of articles from a server. We have got >25000 articles; so I have implemented a pull-to-refresh and infinite scrolling to travel across the title collection.
The ones downloaded persist using core data; NSFetchedResultsController is used to automatically update the UITableView.
However, I have implemented the infinite scrolling to be in both direction; up and down. Since the user will be allow to scroll down the 25000 article titles, I have to remove the one that the user has already scrolled. If the user scrolls up, I have to re-insert title above the current one.
Doing so, I have got a moving window inside the article collection.
I display my articles by date group using the section and header.
The problem is that because the infinite scrolling goes in both direction, I often delete or add article at a higher position in the table.
Infact to achieve that, I have got to change the predicate associated to NSFetchedResultsController.
This result by scroll being messed up. I have made it jump back to the position where it was supposed to be ish. It is not nice because it is a jump (animation:NO), if I put the animation ON, it goes all around the place before going back to the right position. And the position is not exactly the one it should be.
I am not sure I well explained my problem. I think the problem might be in the way I am using the UITableView but I am not sure how I should use it to make this better.
Cheers
If you only store article titles in Core Data, I think it can handle 25.000 titles.
However I think that the problem you've got is with the pagination of the visible elements of the table
Here is a link that I used to handle something that you requested. You'll have to tweak a little bit to use Core Data and a remote source.
Please post some code if you can so we can have a look.

Resources