2009-06-14 11 views
0

난이 배열 여기 로 사전 충전하는 기능을 사용하고하기 기능 [자기 getFlashCard 호출시 배열 flashcardsNamesList가 flashCardsId 매번 변화 위의 코드에서 코드아이폰의 nsdictionary에서 값을 가져 오는 방법은 무엇입니까?

-(void)getAllFlashCardsNames 
{ 
if ([listofitems count]==0) 
    listofitems = [[NSMutableArray alloc] init]; 
else 
    [listofitems removeAllObjects]; 

for(int i=0;i<listOfCategoryId.count;i++) 
{ 
    int j=[[listOfCategoryId objectAtIndex:i]intValue]; 
    [self getFlashCard:j];  
    NSArray *flashCardsNames = flashCardsNamesList; 
    NSArray *flashCardsids = flashCardsId; 
    NSLog(@"FLash Card Ids %@",flashCardsids);  
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:flashCardsNames,@"flashCards",flashCardsids,@"flashCardId",nil]; 
    [listofitems addObject:dictionary]; 

} 

}

에게이다 J ]; j는 listOfCategoryId 배열에서 오는 categoryid를 변경하는 매개 변수입니다.

어떻게 사전에서 값을 가져 옵니까? uitableview의 다른 섹션에 다른 flashcardsNames를 표시하고 싶습니다. 여기

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
return [listofitems count]; 

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section { 
    NSDictionary *dictionary =[listofitems objectAtIndex:section]; 
    NSLog(@"dictionary=%@",dictionary); 
    NSArray *array =[dictionary objectForKey:@"flashCards"]; 
    NSLog(@"array=%@",array); 
    NSLog(@"Section Count = %d",array.count); 
    return array.count; 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    CustomCell *cell = (CustomCell *)[tableViewdequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) {  
     cell = [[[CustomCell alloc] initWithFrame:CGRectZero  reuseIdentifier:CellIdentifier] autorelease];  
    } 

    NSDictionary *dictionary =[listofitems objectAtIndex:indexPath.section]; 
    NSArray *array =[dictionary objectForKey:@"flashCards"]; 
    NSArray *array1=[dictionary objectForKey:@"flashCardId"]; 
    NSString *cellValue=[array objectAtIndex:indexPath.row]; 
    NSString *cellValue1=[array1 objectAtIndex:indexPath.row]; 
    [cell.FlashCardsNames setText:cellValue]; 
    [cell setFlashCardId:[cellValue1 intValue]]; 
    return cell; 
} 

하지만 방법 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

답변

3

라고되지 않고 호출되지 않습니다 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 방법을 검색하는 데 사용하여 코드 메신저입니다

메서드가 구현 된 개체를 테이블보기의 데이터 원본으로 설정 했습니까? 및 UITableViewDelegate 프로토콜을 준수해야하는 다른 개체로 일부 작업을 처리합니다. IB 또는 프로그래밍 방식으로 테이블보기의 dataSourcedelegate으로 개체를 설정해야합니다 (데이터 원본과 대리자는 다른 개체가 될 수 있지만 일반적으로 같은 개체 임). 그것에 대해 더 자세히 설명하는 this article을 살펴보십시오. 이 작업이 완료되면 tableView:cellForRowAtIndexPath:tableView:numberOfRowsInSection: 메쏘드를 처리해야하며,이 메쏘드는 테이블 뷰에 의해 객체에서 호출됩니다. 또한

, 라인은 :

if ([listofitems count]==0) 
    listofitems = [[NSMutableArray alloc] init]; 

이해가되지 않습니다. 배열이 할당되었는지 여부를 확인 중이라고 가정하고 할당하지 않은 경우 배열을 할당한다고 가정합니다. 배열 이 할당되어 있지 않으면 nil이되므로 count을 보내는 것은 효과가 없습니다. 이전에 할당되었지만 할당 해제되었지만 이 아닌 경우 nil으로 되 돌린 후은 잘못된 포인터가되어 응용 프로그램이 중단됩니다.

하위 클래스에 구현하면 awakeFromNib 메서드 또는 applicationDidFinishLaunching: 메서드에서 할당하는 것이 더 좋습니다. dealloc 방법으로 출시하는 것을 잊지 마세요.

+0

메서드가 구현 된 개체를 테이블보기의 데이터 원본으로 설정 했습니까? 이것은 무엇을 의미합니까 ??? –

+0

내 편집 –

+0

에서 tableView : numberOfRowsInSection : 메서드가 호출되었지만이 줄은 배열의 0 개 객체를 반환합니다. NSArray * array = [dictionary objectForKey : @ "flashCards"]; 나는 여기에 갇혀있다. –

관련 문제