0

我想获取存储在数组中的对象的数据。但我不知道如何:/

这是我的对象的类类型:

#import <Foundation/Foundation.h>

@interface Account : NSObject

@property(strong, nonatomic) NSString *accountNumber;
@property(strong, nonatomic) NSString *accountName;

@end


Account *model = [[Account alloc]init];

    for(int i=0; i<NUMBER_OF_CELL; i++){

        [model setAccountName:[NSString stringWithFormat:@"Account %d",i]];
        [model setAccountNumber:[NSString stringWithFormat:@"Number %d",i]];

        [_accountArray addObject:model];

    }

我在 UITableView 中列出了这个:

cell.accountLabel.text = ?

谢谢你的帮助!最好的祝福,

4

3 回答 3

2
Account *model = [_accountArray objectAtIndex:[indexPath row]];
cell.accountLabel.text = model. setAccountName;
于 2013-03-19T12:09:29.133 回答
1

你做错了。帐户对象仅创建一次。这样您就只能看到一个对象。

使用下面的代码。

for(int i=0; i<NUMBER_OF_CELL; i++){

    Account *model = [[Account alloc]init];

    [model setAccountName:[NSString stringWithFormat:@"Account %d",i]];
    [model setAccountNumber:[NSString stringWithFormat:@"Number %d",i]];

    [_accountArray addObject:model];

}

并显示数据使用下面的代码:

Account *model = [_accountArray objectatIndex:indexpath.row];
cell.accountLabel.text = model.accountName;

希望这会帮助你。

祝一切顺利 !!!

于 2013-03-19T12:12:39.910 回答
0

可以使用以下代码实现

Account *model = [_accountArray objectatIndex:indexpath.row];
cell.accountLabel.text = model. AccountName;
于 2013-03-19T12:09:48.210 回答