Search code examples
iosobjective-cxmlfeeddata-import

How to dynamically import static information, including an image, into an ViewController


I was wondering whether it was possible to import static information, in my case an image, title and a short description - per item, in a UIViewControlller dynamically?

I'm (trying to) create an app that, for the current UIViewController I'm working on, shows the cooperating partners from the company in a list view. Each of them is shown as an item, containing an image (logo), the company name below and below that a paragraph of information about the company.

I was thinking of something like importing an XML feed (no experience with), such as

<object>
    <img src="/images/logo1.png">
    <title="Lorem ipsum>
    <description="lalalalalalalala"
</object>

<object>
    <img src="/images/logo2.png">
    <title="Lorem second one>
    <description="lalalalalalalala"
</object>

Something like this mockup

By simply importing such thing, I don't have to make up the whole page, calculate how long the UIScrollView would have to be and don't have to adjust it every time a partner gets added or removed. And it might be quite more clear than a whole view controller.


Solution

  • You have to divide the task into smaller steps.

    1. Read the data from an XML file using NSXMParser.
    2. Show the data in a UICollectionView.

    The XML part is quite easy. There are many tutorials on the Internet that cover this. For example this one:

    Second step can be more complicated depending on what kind of a layout you want to achieve. If it is a standard flow layout, the implementation will be fairly simple. Again, there is dozens of tutorials on setting up a UICollectionView. Example:

    Alternatively, you can use UITableView to show your data. In this case, the implementation would be simpler than for UICollectionView.

    More reading: