2011-12-21 2 views
-3

최신 UITableView 인덱싱. 내가 좋아하는 몇 가지 데모 데이터,어떻게 UITableView 인덱싱?

tableDataArray = [[NSMutableArray alloc] init]; 

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; 
[dict setObject:[NSString stringWithFormat:@"Thomas Cook"] forKey:@"Name"]; 
[dict setObject:[NSString stringWithFormat:@"Dean"] forKey:@"Position"]; 
[dict setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"]; 
[dict setObject:[NSString stringWithFormat:@"67-876-65433"] forKey:@"PhoneNo"]; 
[tableDataArray addObject:dict]; 

NSMutableDictionary *dict1 = [[NSMutableDictionary alloc] init]; 
[dict1 setObject:[NSString stringWithFormat:@"John Appleseed"] forKey:@"Name"]; 
[dict1 setObject:[NSString stringWithFormat:@"Department of accounting"] forKey:@"Position"]; 
[dict1 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"]; 
[dict1 setObject:[NSString stringWithFormat:@"45-876-65433"] forKey:@"PhoneNo"]; 
[tableDataArray addObject:dict1]; 

NSMutableDictionary *dict2 = [[NSMutableDictionary alloc] init]; 
[dict2 setObject:[NSString stringWithFormat:@"Amar Smith"] forKey:@"Name"]; 
[dict2 setObject:[NSString stringWithFormat:@"Department of Human Resource"] forKey:@"Position"]; 
[dict2 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"]; 
[dict2 setObject:[NSString stringWithFormat:@"54-876-65433"] forKey:@"PhoneNo"]; 
[tableDataArray addObject:dict2]; 

NSMutableDictionary *dict3 = [[NSMutableDictionary alloc] init]; 
[dict3 setObject:[NSString stringWithFormat:@"Mary Cold"] forKey:@"Name"]; 
[dict3 setObject:[NSString stringWithFormat:@"HOD of Computer Department"] forKey:@"Position"]; 
[dict3 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"]; 
[dict3 setObject:[NSString stringWithFormat:@"52-876-65433"] forKey:@"PhoneNo"]; 
[tableDataArray addObject:dict3]; 

NSMutableDictionary *dict4 = [[NSMutableDictionary alloc] init]; 
[dict4 setObject:[NSString stringWithFormat:@"John Jobs"] forKey:@"Name"]; 
[dict4 setObject:[NSString stringWithFormat:@"Department of Physics"] forKey:@"Position"]; 
[dict4 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"]; 
[dict4 setObject:[NSString stringWithFormat:@"12-876-65433"] forKey:@"PhoneNo"]; 
[tableDataArray addObject:dict4]; 

NSMutableDictionary *dict5 = [[NSMutableDictionary alloc] init]; 
[dict5 setObject:[NSString stringWithFormat:@"Clark Kristan"] forKey:@"Name"]; 
[dict5 setObject:[NSString stringWithFormat:@"Contact Person"] forKey:@"Position"]; 
[dict5 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"]; 
[dict5 setObject:[NSString stringWithFormat:@"65-876-65433"] forKey:@"PhoneNo"]; 
[tableDataArray addObject:dict5]; 

그래서, 내가 인덱스 jQuery과를 만들 수 있습니다. 위의 데이터 형식을 사용하여 내 UITableView 대리자 및 데이터 소스 메서드는 어떻게됩니까?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 
} 

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 
} 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 
} 

감사

+0

귀하의 질문을 정교하게 기입하십시오. 어떻게 데이터를 표시 하시겠습니까? – Maulik

+0

@Maulik, Name의 첫 번째 문자를 사용하여 tableview 데이터를 인덱싱하고 싶습니다. – Tirth

답변

0
당신은 당신이 당신의 색인 목록에 표시하고 (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { }에 해당 배열을 반환하려면 제목의 배열을 만들 필요가

및 추가 정보를 읽어 사과 문서에 대해이 (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { } just return the index.

에서 - http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

+0

Name의 첫 번째 문자를 사용하여 테이블 데이터를 인덱싱하려는 경우 해당 문자에 따라 섹션 테이블 헤더의 제목이어야합니다. – Tirth

+0

예 이러한 모든 문자의 배열을 만들어야하고 두 번째 대리자는 해당 문자를 배열의 인덱스에서 검색합니다. – saadnib

+0

이 기사를 보면 도움이 될 것입니다. - http://www.iphonesdkarticles.com/2009/01/uitableview-indexed-table-view.html – saadnib