Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I should get the obvious question out of the way before anyone starts dwelling too deep into this - do you have some mechanism of reloading the data after you add a new card (e.g. call [<code>tableView reloadData</code>] from the <code>CardWalletViewController</code>)? I didn't see anything like that, and I've always used this whenever I add something new to a table.*</p> <p>*If the table contains too much data, you may want to reload only a part of it.</p> <h2>Update 1: Class Inheritance</h2> <p>Every Objective C class has to inherit from some other class in the hierarchy. By default, unless you say otherwise, all of your custom classes will inherit from NSObject, which is the most generic object out there (equivalent of Object, if you've done Java programming). Changing the parent class is done by simply changing the class after the <code>:</code> in your interface declaration. So when you say<br> <code>@interface CardWalletViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt;</code><br> what you are saying is "declare a <code>CardWallerViewController</code> custom class that inherits from <code>UIViewController</code> and implements the <code>UITableViewDelegate</code> and <code>UITableViewDataSource</code> protocols" (if you don't know what protocols are, ask). </p> <p>Now, back to your question. Changing the parent class should be easy now - you just change that <code>: UIViewController</code> to <code>: UITableViewController</code> and you are done. After you do this, your CardWallerViewController (also, "Waller", really?) will behave like a <code>UITableView</code>, not like a generic <code>UIView</code>. When doing this, you will also not need to tell it to implement the delegate and dataSource protocols - <code>UITableViewController</code> does that by default. </p> <p>As a final note, when you add new files to your Xcode project, you can tell the program which class you want to inherit from. It defaults to UIView for views, but that's simply because this is the most generic view class. As you begin to use more specific classes (<code>UITableViewController</code>, <code>UIPickerViewController</code>, <code>UITableViewCell</code>, to name a few), changing the parent class off the bat will prove to be more than helpful.</p> <h2>Update 2: UITableViewCells</h2> <p>That for-loop you've got going there is a (relatively) lot of work you don't need to do. Since your table corresponds directly to your myWallet property, this means that the cell in row N of your table will represent the card at index N of your array. You can use that to your advantage. In the <code>tableView:cellForRowAtIndexPath:</code> method, you tell the program what to do with the cell at the specific indexPath (which is really just section + row for that table). The trick is, this method instantiates the cells one at a time. So instead of doing the for-loop, you can just say (at the end)<br> <code>cell.textLabel.text = [self.myWallet objectAtIndex:indextPath.row].name;</code> </p> <p>For any cell in row N, this will look at the Nth Card object inside <code>myWallet</code> and use its name to set the cell's <code>textLabel.text</code>. If it gives you problems, save <code>[self.myWallet objectAtIndex:indextPath.row]</code> in some tempCard object, and then do <code>cell.textLabel.text = tempCard.name</code>. This is also the proper way to populate cells in a tableView - you only care about one cell at a time, because that's how the method works anyway. Imagine if you had 1,000,000 Cards inside your array - doing the for-loop would force the program to go through the array 1,000,000 times for each cell. Say hello to a 1,000,000,000,000 operations :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload