我可以在右侧显示类似于ipod上的歌曲视图的索引。在搜索期间,索引栏会自动最小化。当我回到我的实际表格视图时,索引大小很小,它只显示几个字母。如何停止调整大小?
答案 0 :(得分:2)
你必须在viewController.m文件中放置适当的UITableView委托方法。
例如我已经放置了以下代码。
请仔细阅读评论。
#pragma mark -
#pragma mark Table view data source
// an array count which has values for index - like A,B,C etc.
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//return [NSArray arrayWithArray:keys];
return [keys count];
}
// an array which has values for index - like A,B,C etc.
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return keys;
}
// return how many number of rows are required for each section.
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[dMain valueForKey:[keys objectAtIndex:section]] count];
}
// return title of section
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [keys objectAtIndex:section];
}
// create each row for different sections
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"%i %i",indexPath.row,indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font=[UIFont fontWithName:@"Helvetica" size:12];
//cell.textLabel.text=[[[objects objectAtIndex:indexPath.row] valueForKey:@"marketname"] stringByReplacingOccurrencesOfString:@"_and_" withString:@"&"];
cell.textLabel.text=[[[[dMain valueForKey:[keys objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:@"marketname"] stringByReplacingOccurrencesOfString:@"_and_" withString:@"&"];
}
return cell;
}