How to use NSTimer with data from NSURL pass to NSXMLParser display in TableView

How to use NSTimer with data from NSURL pass to NSXMLParser display in TableView

I have application display data from web server by PHP gen' to XML

In my xcode i use NSURL for connect to PHP file (in web server) and use NSXMLParser to read XML data put value to array and final display on TableView

I want to see data in TableView live update or update every x time

I think i can use NSTimer but i don't know how i can where i can put NSTimer to the code in xcode


In short, something like:

// Schedule a timer repeating every 2 seconds
[NSTimer scheduledTimerWithTimeInterval:2.0

Longer version:

You need to call -doParse from a timer, fetch data, do parsing, and reload the data.

In order not to block main thread, you must NOT call [[NSXMLParser alloc] initWithContentsOfURL:theURL] from main thread.


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
      NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];
      // finish parsing
      dispatch_async(dispatch_get_main_queue(), ^{
          [tableView reloadData];

And call -doParse with a NSTimer from -viewDidLoad :

[NSTimer scheduledTimerWithTimeInterval:2.0

Further reading: WWDC 2012 Session 211 - Building Concurrent User Interfaces on iOS.

Need Your Help

Define Type of Immutable Map With Builder

java collections guava

I am trying to make a Map<BooleanSupplier, List<String>> as part of my flow I make the suppliers and then try to use an immutable map builder.

PHP datetime formatting in echo

php date

PHP noob. Having trouble getting a PHP date format to execute here: