New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Updating the item view with the feed items

From: iOS SDK and SQLite: Building Data-Driven Apps

Video: Updating the item view with the feed items

At this point, we have a working parser running in a separate thread that's updating items in the database. Now, it's time to update the ItemTableView from the database, and now that all the heavy lifting has been done, this becomes pretty simple. We'll start one by making a working copy of BWRSS-XML-04. In this case, I'm going to use the -done version. You can use the one that you completed in the last movie, if you've been following along with the exercises. I'm going to rename this to BWRSS-XML-05, and I'm going to open it in Xcode by double-clicking on the Xcode project file.

Updating the item view with the feed items

At this point, we have a working parser running in a separate thread that's updating items in the database. Now, it's time to update the ItemTableView from the database, and now that all the heavy lifting has been done, this becomes pretty simple. We'll start one by making a working copy of BWRSS-XML-04. In this case, I'm going to use the -done version. You can use the one that you completed in the last movie, if you've been following along with the exercises. I'm going to rename this to BWRSS-XML-05, and I'm going to open it in Xcode by double-clicking on the Xcode project file.

I'm going to go ahead and expand this and select the iPhone Simulator there and select the ItemsTableViewController here. I'm going to minimize this Utilities Bar, and that way we have plenty of screen real estate here to look at our code. So, you notice as we add items to the database here, we have this little NSLog that displays the items. If I go ahead and run this in the Simulator-- I've selected the iPhone Simulator, and I'm going to run this.

You see that as I select a feed, we get the output down here in the log, and that's from this NSLog here. So, we have the item title, we have the pubDate, and we have the URL. I'm going to stop the Simulator by pressing Command+Period, and we'll go ahead and minimize this so that we have some room here. Now, what we have to do is to update the TableView from the database. So, there are couples of steps to that.

We're going to come back up here to our Table view data source section and the number of sections in the TableView is going to be one because there's always just one section. We don't use the Sections Feature for this application. Number of rows in section is already filled out here. We have the itemRowIDs getting updated from the getItemIDs in the database and then we return the count and so that's the number of rows in the section. I'm going to press Command+S here on my keyboard to save.

Now, our cellForRowAtIndexPath, this is a bit of code, so we're going to go ahead and read this from a txt file, coming back here into Finder, our 05-Table.txt. We're just going to grab this whole thing because this is all just that one method. I'm going to select all with Command+A and Command+C to copy and come back here into Xcode, and I'm going to select this method here, cellForRowAtIndexPath. Select the entire method and paste and then we can look at the code here in Xcode.

I'm going to press Command+S on my keyboard to save. Our CellIdentifier, we want to come back over here into the iPhone storyboard and select our cell and bring up our Utilities View. You see the Identifier here says ItemCell, all right? If we come back over here to our TableViewController, we see that it says ItemCell, so it does match. That's important. If it doesn't match, we know that the cell won't get updated.

Now, we get the FeedItem based on the indexPath.row, and now we have what I call the clever variable font size trick. It's really very simple. All we're doing here is we're taking the text that's going to go in the ItemCell, and we're looking at whether it would take up more than one line, and if it takes up more than one line, then we're using a smaller font size, and we're using a larger font size if it takes up just the one line. I'll show you that when we run this.

Again, we're reformatting the date. This time we're taking an SQLDate, and we're making it into a displayable date, and if we look down here in our Utility methods, SQLDateToDate, that puts it in an NSDate format and then we have dateToLocalizedString, which puts it in a localized format. If we come back up here to our cellForRowAtIndexPath, you see we call dateToLocalizedString, based on the SQLDateToDate, and that all gets loaded into the detailTextLabel.

Now just before we run this, we want to come back up here to addItemsToList, and we just want to take out this NSLog line here. We're not going to need that anymore because we're now updating the TableView. So, I'll save this, and we've got iPhone Simulator selected, and we'll go ahead and we'll run this in the Simulator, and I'll select one of these feeds, and there we have it. Now, we have our data being displayed, and you'll notice we have the title and the date in the localized format. If I go ahead and look up one of these other entries, you'll notice that we have two different font sizes.

This line here InDesign FX is in a larger font than these that have more than one line. What can happen here as well, I don't have an example of it here, but I think I have an example of it in this one. You'll notice that some of these are in a smaller size because they wouldn't fit all on one line in the larger size. So, this one is a larger size, this one is a larger size, and these three are actually the smaller size and they don't wrap around to the second line, but if they were in the larger size, they would and so they get that smaller font size anyway.

So, that's that clever font-size trick that's used in cellForRowAtIndexPath. Now, we have a working TableView for the feed items. It reads the RSS feed from the net, it parses it in a separate thread, it stores the results in the database, and it reads the results from the database for display in the TableView. We'll implement a WebView for displaying the items in a later chapter.

Show transcript

This video is part of

Image for iOS SDK and SQLite: Building Data-Driven Apps
iOS SDK and SQLite: Building Data-Driven Apps

41 video lessons · 6326 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 8m 29s
    1. Welcome
      57s
    2. Exercise files
      2m 17s
    3. Course overview
      3m 4s
    4. Application overview
      2m 11s
  2. 14m 49s
    1. Prototyping in a testbed
      1m 27s
    2. Building the view controller
      3m 45s
    3. Coding the testbed
      7m 56s
    4. Using the testbed
      1m 41s
  3. 37m 49s
    1. Understanding SQLite in iOS
      1m 41s
    2. Creating an Objective-C interface for SQLite
      9m 57s
    3. Testing the BWDB interface in the sandbox
      7m 1s
    4. Designing a database schema
      8m 7s
    5. Supporting the application with a specific interface
      7m 7s
    6. Using C pointers with automatic reference counting (ARC)
      3m 56s
  4. 21m 18s
    1. Understanding the table view
      1m 33s
    2. Creating the view controller
      6m 39s
    3. Reading from the database
      13m 6s
  5. 33m 50s
    1. Understanding the parsing process
      1m 57s
    2. Creating the item view controller
      12m 25s
    3. Reading data from the internet
      5m 30s
    4. Parsing the feed with NSXMLParser
      8m 2s
    5. Updating the item view with the feed items
      5m 56s
  6. 40m 14s
    1. Understanding the modal view
      1m 47s
    2. Constructing the view controller
      15m 5s
    3. Finding a feed link in a web page
      8m 55s
    4. Parsing the feed with NSXMLParser
      5m 4s
    5. Delegating back to the parent view
      6m 11s
    6. Deleting feeds
      3m 12s
  7. 21m 5s
    1. Creating the web view class
      12m 33s
    2. Coding the web view
      5m 25s
    3. Viewing pages in Safari
      3m 7s
  8. 14m 3s
    1. Understanding the iOS preferences system
      1m 23s
    2. Creating the preferences plist in Xcode
      7m 20s
    3. Reading preferences in your application
      5m 20s
  9. 6m 15s
    1. Adding pull-to-refresh functionality
      2m 34s
    2. Implementing the pull-to-refresh gesture for iOS 6
      3m 41s
  10. 27m 1s
    1. Understanding split view
      1m 4s
    2. Coding the table views
      11m 24s
    3. Implementing the iPad detail view
      6m 35s
    4. Implementing the iPad modal view
      7m 58s
  11. 35s
    1. Goodbye
      35s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.