开发者

iPhone table view, using NSDictionary & plist

I'm populating a UITableView with NSDictionary and dictionaryWithContentsOfFile plist.

In the开发者_开发知识库 plist I have 3 rows, each row has an array.

I don't know what the id/index of the row will be.

Under:

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    cell.textLabel.text = @"Blah";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

For cell.textLabel.text, how do I do something like [self.myList getKey]; where getKey will return the key/id of the row?


If you want the Nth key from an NSDictionary, you could always do this:

[[myDict allKeys] objectAtIndex:n];

However, I suspect you don't actually want that since the keys are not necessarily in the order you might think. Perhaps what you should be doing instead is

NSArray* a = [NSArray arrayWithContentsOfFile:aPath];

So long as your plist is the right structure, it should give you the order you want

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜