2013-03-19 5 views
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]; 

    } 

내가 jQuery과이 목록 : 당신이 도움을

cell.accountLabel.text = ? 

감사를! 안부,

답변

1

를 사용하여 acheived 수 있습니다. 계정 개체는 한 번만 생성됩니다. 그래서 당신은 하나의 대상만을 보게됩니다.

아래 코드를 사용하십시오.

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; 

희망이 당신을 도울 것입니다.

모두 최고 !!!

+0

이 방법을 시도했지만 배열의 마지막 값만 있습니다. 배열의 초기화는 viewDidLoad 메서드에 있습니다. – Lapinou

+0

어디서 _accountArray를 할당합니까? – Yashesh

+0

NSArray 할당 코드를 표시 할 수 있습니까? – Yashesh

2
Account *model = [_accountArray objectAtIndex:[indexPath row]]; 
cell.accountLabel.text = model. setAccountName; 
+0

완벽하게 작동합니다. – channi

0

당신은 잘못하고있는 다음 코드

Account *model = [_accountArray objectatIndex:indexpath.row]; 
cell.accountLabel.text = model. AccountName; 
관련 문제