【发布时间】:2012-01-24 23:45:54
【问题描述】:
我更新了 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:@"thomascook@xyz.com"] 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:@"john@xyz.com"] 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:@"amsmith@xyz.com"] 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:@"coldmary@xyz.com"] 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:@"jobs@xyz.com"] 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:@"kristan@abc.com"] forKey:@"Email"];
[dict5 setObject:[NSString stringWithFormat:@"65-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict5];
所以,我想创建索引 UITableView。我的 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 {
}
谢谢
【问题讨论】:
-
请详细说明您的问题。您希望如何显示数据?
-
@Maulik,我想使用名称的第一个字符来索引 tableview 数据。
标签: iphone ipad ipod-touch