Reputation: 5132
Using this tutorial (http://www.raywenderlich.com/5492/working-with-json-in-ios-5), I understand how to parse and display contents in JSON to a label. However, the example has a set number of labels.
How would I dynamically change the number of labels displayed based on the number of contents in the JSON? The user would scroll down for each label. In the example from that link, there would be 20 different labels for the 20 different loans.
http://api.kivaws.org/v1/loans/search.json?status=fundraising
Upvotes: 2
Views: 186
Reputation: 726849
You can create UILabel
objects dynamically, and add them to the view where you need them. It should be a UIScrollView
. Here is a question and answer that discuss this approach in depth.
However, this is not the best approach that you can take, because as the number of labels grows, you start to run out of resources. This slows down your scrolling, among other things, and increases the possibility of running out of memory.
The idiomatic iOS solution to a situation when you need a list of labels that grows dynamically is to use UITableView
. This class solves the potential resource issues by reusing the cells as they get scrolled off the screen. Although it is possible for you to implement a similar approach with your own scroll view, it would take you considerable effort, but would not look "native" to the users of your application.
Upvotes: 2