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

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 :-)

Related

Creating a menu in iOS

I'm currently creating an update of my iOS application and I'm a bit stuck. I've tried to googling around but cannot find a decent answer on this.
I've a menu which links to different views. And I'm not really sure if I've done it the best method.
I've created a view, and added the links into a stack view. Should I considering changing it all to a tableview? or a collection view? Or maybe there's another way?
The current look:
Should I change this to a tableview? collection view? or something else? Or just let it stay as it is?
If the number of items in your menu changes at runtime and is large, you should use a table view, because a table view is good for efficiently displaying a screen's worth of items from a large list of items.
If the contents of your menu is small (under maybe two screenfuls of items) and fixed at compile time and you are using a storyboard, then you could use a table view with static cells, if you can make it look the way you want.
If the contents of your menu is small, then you can use a stack view (inside a scroll view) if that is easier for you. There is no particular advantage to using a table view over a stack view to display a small amount of content, unless you need other features of the table view (like the ability to select/deselect rows).
Based on the screen shot you posted, I'd either use a table view with static cells (since the screen shot is from a storyboard) or a stack view, depending on whether I can get the appearance I want from a table view. If, as in the screen shot, the buttons must be centered vertically, I'd use a stack view, because it's easier to vertically center the content with a stack view.
Look, the fact of have many itens on your screen is clear on the mobile applications, to make it easy, we have collecions view like UITableView and UICollectionView. On the UITableView's case, this implements the scrolling and have methods do handle the operations' list, you can see the documentation to check these methods: https://developer.apple.com/documentation/uikit/uitableview.
Main reasons to use UITableView
Implements scroll behavior.
Independent of size screen you can access all itens.
Easy to detect interactions like tap on cell.
Easy to make changes, like insert and remove content.
The UITableView exists precisely to solve problems like you has.

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.

How can I make my UITableView request the X next cells that are outside the visible table?

I would like to have my UITableView load 3 or 4 cells outside of the table so that any data to be shown there is already loaded when I scroll down.
I have some images, and data that must be downloaded before it can be shown in the cell.
This causes a visible delay before the images are loaded when scrolling.
I can manually trigger loading of this data by doing it in the UITableViewDataSource tableView:cellForRowAtIndexPath: method. I've done this before, but I'm curious if there's an easier way to do it.
Is there any way to expand the reusable cell pool, or adjust how the cells are loaded/recycled?
EDIT:
To clarify, I have lazy loading of images and data in place.
Everything works fine, I just wanted an easy solution to the "prefetching" problem.
Which can be solved in many ways that has nothing to do with the view itself. Right now you can easily see the images load as you scroll. I just wanted them to load right before they become visible.
You may be looking for an asynchronous table view that loads the data asynchronously.
Apple provides a sample app demonstrating this:
LazyTableImages
Of course, you could pre-cache the data and begin downloading data into your datasource before they scroll.
The general idea is that you are loading data into a datasource (that is separate from the UI), so you can do this at any time (and in the background). You can display temporary data or some type of loading image or spinner if the data isn't loaded yet.
If data of the cell will be loaded when cel becomes visible, you can programmatically scroll the table view by scrolling to the bottom cell and go back to the first cell without animation. Another way would be creating all the cells and placing them into array when your view controller is created, and feed the table from that array that contains already created cells. I think there is no way to extend the cell pool as you are asking. Hope this helps, Good Luck!

ios - Making UIScrollView scroll smoothly

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.

Resources