【发布时间】:2015-05-21 07:43:14
【问题描述】:
我正在尝试在 Objective-C 中制作类似电话簿的应用程序。我使用 NSDictionary 来填充我的UITableViewCell。我得到了正确的标题、索引和部分,但是我无法为每个标题获得正确的副标题。每个标题总是相同的副标题。这是我的代码示例:
@interface TableViewController (){
NSDictionary *sarkilar;
NSArray *sarkilarSectionTitles;
NSArray *sarkilarIndexTitles;
NSArray *subtitles;
}
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
sarkilar = @{@"A" : @[@"Alayına İsyan"],
@"B" : @[@"Bebek"],
@"E" : @[@"Elbet Birgün Buluşacağız"],
@"Y" : @[@"Yusuf Yusuf"]};
subtitles = [[NSArray alloc]initWithObjects:@"Seslendiren: Mustafa Sandal",
@"Seslendiren: Akın",
@"Seslendiren: Ahmet Özhan",
@"Seslendiren: Acil Servis",nil];
sarkilarSectionTitles = [[sarkilar allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
sarkilarIndexTitles = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"];
.
.
.
//and in the cell set up i got this:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableViewCell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *sectionTitle = [sarkilarSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionSarkilar = [sarkilar objectForKey:sectionTitle];
NSString *sarki = [sectionSarkilar objectAtIndex:indexPath.row];
cell.textLabel.text = sarki;
cell.detailTextLabel.text = [subtitles objectAtIndex:indexPath.row];
return cell;
}
如果能提供任何帮助,我将不胜感激!
【问题讨论】:
标签: ios objective-c uitableview nsdictionary subtitle