Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding sections to a plist for Xcode for use in Cocoa touch Table View
    primarykey
    data
    text
    <p>I am a beginning iPhone SDK programmer. I built a simple practice application I am trying to use to learn more about table views. It's an app that loads football teams from a plist and displays them in a table view with their stadium name and logo. Tapping the team goes to a detail view for that team.</p> <p>I am trying to understand how to add sections to this, so that I might have a couple of teams in one section and others in another section, etc.</p> <p>I would assume I need to both re-structure my plist and change the code to read arrays from the different levels of the plist?</p> <p>To begin, I had a plist with the root array consisting of 3 dictionaries, one for each team. Each dictionary had 3 keys, "name" "stadium" and "logo". This works fine. I am loading it via:</p> <pre><code>NSString *path = [[NSBundle mainBundle] pathForResource:@"teams" ofType:@"plist"]; teams = [[NSMutableArray alloc] initWithContentsOfFile:path]; </code></pre> <p>and then</p> <pre><code>// Configure the cell. NSDictionary *team = [teams objectAtIndex:indexPath.row]; cell.textLabel.text = [team objectForKey:@"name"]; NSString *imgPath = [team valueForKey:@"logo"]; cell.imageView.image = [UIImage imageNamed:imgPath]; cell.detailTextLabel.text =[team objectForKey:@"stadium"]; return cell; </code></pre> <p>No problem. But now I wanted the sections, so I changed my plist to:</p> <pre><code>&lt;array&gt; &lt;dict&gt; &lt;key&gt;teams 1&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;name&lt;/key&gt; &lt;string&gt;Packers&lt;/string&gt; &lt;key&gt;stadium&lt;/key&gt; &lt;string&gt;Lambeau Field&lt;/string&gt; &lt;key&gt;logo&lt;/key&gt; &lt;string&gt;packers.jpg&lt;/string&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;name&lt;/key&gt; &lt;string&gt;Jets&lt;/string&gt; &lt;key&gt;stadium&lt;/key&gt; &lt;string&gt;Giants Stadium&lt;/string&gt; &lt;key&gt;logo&lt;/key&gt; &lt;string&gt;jets_logo.jpg&lt;/string&gt; &lt;/dict&gt; &lt;/array&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;teams 2&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;name&lt;/key&gt; &lt;string&gt;Cincinnati Bengals&lt;/string&gt; &lt;key&gt;stadium&lt;/key&gt; &lt;string&gt;Paul Brown Stadium&lt;/string&gt; &lt;key&gt;logo&lt;/key&gt; &lt;string&gt;bengals.jpg&lt;/string&gt; &lt;/dict&gt; &lt;/array&gt; &lt;/dict&gt; </code></pre> <p> </p> <p>And I am unsure how to modify the viewDidLoad to assign the sections to one NSArray and the teams "level" to another array.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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