Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if I understand your question, but each key can have only one object associated with it. In your case, you're using an NSString object. If you replaced the NSString with some object that you create, say AnObjectWithAThingAndAPersonAndAPlace, you could have multiple attributes associated with each key.</p> <hr> <p>I think I understand what you want now. What you want is not an object with arrays associated to it, but an array of objects. You can do it with NSDictionary objects. </p> <pre><code>- (void)setupArray { NSMutableArray *objectArray = [[NSMutableArray alloc] init]; NSMutableDictionary *object1 = [[NSMutableDictionary alloc] init]; [object1 setObject:@"Apple" forKey:@"thing"]; [object1 setObject:@"Alex" forKey:@"person"]; [object1 setObject:@"Alabama" forKey:@"place"]; [object1 setObject:@"Azure" forKey:@"color"]; [objectArray addObject:object1]; NSMutableDictionary *object2 = [[NSMutableDictionary alloc] init]; [object2 setObject:@"Banana" forKey:@"thing"]; [object2 setObject:@"Bill" forKey:@"person"]; [object2 setObject:@"Boston" forKey:@"place"]; [object2 setObject:@"Blue" forKey:@"color"]; [objectArray addObject:object2]; datasource = [NSArray arrayWithArray:objectArray]; } </code></pre> <p>Then in your UITableViewDataSource method</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = [indexPath row]; NSDictionary *object = [datasouce objectAtIndex:row]; ... } </code></pre> <p>and you can retrieve all the strings for that object.</p> <p>If I were to do something like this, I would probably create a plist file containing the array. Then your setupArray method could look like this:</p> <pre><code>- (void)setupArray { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"YourFileName" ofType:@"plist"]; NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:filePath]; datasource = (NSArray*)[plistData objectForKey:@"ObjectsForTableView"]; } </code></pre> <hr> <p>I though I would add a few more comments...In case it isn't obvious, the objects you add to your dictionary don't have to be NSStrings, they can be any object, such as an NSNumber, which may be useful for you in the case of your baseball players. Also, you may wish to create a custom player object instead of using an NSDictionary. And you may want to have something like a Core Data database where the players are stored and retrieved (instead of hard coding them or getting them from a plist file). I hope my answer can get you started on the right path though.</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