Today we continue our fourth lesson, in which we started writing a parser for news from a blog site. In this part of the lesson, we will describe how to display comments for each news, and we will also write a Pull to Refresh function for a table with records. So, at the heart of the Loutskiy CMS engine is the function of comments to posts, which we will display in our application. Their display will be carried out on a separate ViewController, and the output will take place in the UITableView table. We will receive the comments themselves from the MySQL database in JSON format. To do this, from the DetailViewController class, we will pass the unique ID number of the post page to the CommentsViewController class. This is necessary to make a request to the API script so that it displays exactly the comments that refer to this entry. Development under iOS In the comment block we will display the username, date and text. Since we are making the cell height in the table static, and the comment text may be too large, we will output it through the TextView. That is, we will be able to scroll inside a block with a comment. And receiving a comment will be tied to the same JSONLoader class. Now we only need to implement the Pull to refresh function, which allows us to update the data in the table by pulling a swipe from top to bottom. This format is very convenient, to activate it add the following code to the viewDidLoad function:
UIRefreshControl refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget: self action: @selector (refresh 🙂 forControlEvents: UIControlEventValueChanged]; [self.tableView addSubview: refreshControl];
VIDEO Download project sources In order not to miss anything, subscribe to my YouTube channel.