Plist负载中出现奇数

时间:2013-06-10 22:43:36

标签: ios xcode

我正在从我的文档文件夹中加载一个Plist,我有7条记录...检查如下:但是我的Master View表只显示了5,这是通过我的“numberOfRowsInSection:return [accounts count] ...来确认的...代码在下面,我错过了什么地方......有设置:注意:数据是虚构的

   Account =     (
        "BOA Mortgage",
        "Citibank Visa",
        HOA,
        "Toyota Finance",
        "CitiBank Account",
        West,
        "Wells Fargo"
    );
    Balance =     (
        "5678.00",
        1099,
        "145.00",
        "21000.00",
        "4500.00",
        1200,
        450
    );
    DayDue =     (
        8,
        3,
        6,
        26,
        5,
        3,
        23
    );
    MinAmount =     (
        "1899.00",
        "1200.00",
        "329.00",
        "583.84",
        "225.00",
        45,
        35
    );
    Number =     (
        "8837430-002",
        "29932843-00",
        45225028,
        452308582345,
        25390403232,
        1234578,
        1234566
    );
}

- (void)viewDidLoad
{
    NSLog(@"loading data");
    self.navigationItem.title=@"Accounts";
//    NSString *accountFile = [[NSBundle mainBundle] pathForResource:@"Accounts2" ofType:@"plist"];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [paths objectAtIndex:0];
    NSString *plistPath = [documentPath stringByAppendingPathComponent:@"Accounts2.plist"];
    accounts = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    NSLog(@"Accounts contains : %@", accounts);
    account = [accounts objectForKey:@"Account"];
    NSLog(@"account %@", account);
    number = [accounts objectForKey:@"Number"];
    dueDay = [accounts objectForKey:@"DayDue"];
    minAmount = [accounts objectForKey:@"MinAmount"];
    balance = [accounts objectForKey:@"Balance"];

    NSLog(@"data loaded");

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
    self.navigationItem.rightBarButtonItem = addButton;
}

以下是来自我的cellForRowAtIndexPath的更多代码...它也只返回5

// 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }


     NSDate *object = _objects[indexPath.row];
     cell.textLabel.text = [object description];

    NSString *nameOfAccount = [account objectAtIndex:indexPath.row];
    cell.textLabel.text = nameOfAccount;
    NSString *accountNumber = [number objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = accountNumber;
    NSLog(@"Index %d", indexPath.row);
    return cell;
}

1 个答案:

答案 0 :(得分:1)

您说在numberOfRowsInSection方法中,您返回[accounts count]。毫不奇怪,这会返回5,因为accounts是您的字典,5是该字典中的条目数:Account,Balance,DayDue,MinAmount和Number。

要解决您的问题,您的方法应该返回[account count]account是字典中的一个数组,其中一个有7个条目。