2009-11-02 1 views
0

첫 번째 문자로 상태의 도시를 구성하는 인덱싱 된 테이블 뷰가 있습니다. NSMutableDictionary는 A, B, C 등의 키로 생성됩니다. 해당 도시가 각각의 배열에 추가됩니다. 예는 :UITableView 인덱싱

지금
Y =  (
    Yatesboro, 
    Yeagertown, 
    York, 
    "York Haven", 
    "York New Salem", 
    "York Springs", 
    Youngstown, 
    Youngsville, 
    Youngwood, 
    Yukon 
); 
Z =  (
    Zelienople, 
    Zieglerville, 
    "Zion Grove", 
    Zionhill, 
    Zionsville, 
    Zullinger 
); 

, 올바른 섹션의 수, 행 섹션 내 및 인덱싱 제어 내 테이블 뷰 하중이와 함께 잘 작동 :

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [cities count]; 
} 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    if([searchArray count]==0) 
     return @""; 
    return [searchArray objectAtIndex:section]; 
} 
// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [[cities objectForKey:[searchArray objectAtIndex:section]] count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 
    NSLog([NSString stringWithFormat:@"clicked index : %i",index]); 
    if (index == 0) { 
     [tableView scrollRectToVisible:[[tableView tableHeaderView] bounds] animated:NO]; 
     return -1; 
    } 
    return index; 
} 

내 문제는 이제 텍스트를 채우고 각 섹션에 대한 텍스트와 테이블 셀의 ... 내가이 정보를 잡을 수있는 방법에 대한 생각?

답변

1

cellForRowAtIndexPath은 필요한 행과 섹션을 모두 포함하는 NSIndexPath 전달 된 매개 변수를 가져옵니다. 자세한 내용은 NSIndexPath UIKit Additions을 참조하십시오. 그와

이 당신의 특별한 경우에 작동 할 수 있습니다 말했다되고 : 바로 (컴파일러에 시도하지 않은)을 가지고 있지만, 지금까지 일반적인 아이디어를 얻을 수있는 경우

- (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]; 
    } 

    NSString *letter = [searchArray objectAtIndex:indexPath.section]; 
    NSArray *city = [cities objectForKey:letter]; 
    cell.text = [city objectAtIndex:indexPath.row]; 

    return cell; 
} 

확실하지 않음 :)

+0

매력적인 남자처럼 일했습니다. 나에게 큰 두통을 안겨 줬다. 감사! – rson