【问题标题】:how to control the index displayed on the tableview如何控制tableview上显示的索引
【发布时间】:2026-01-27 17:10:01
【问题描述】:

我可以在右侧显示一个索引,类似于 ipod 上的歌曲视图。在搜索过程中,索引栏会自动最小化。当我回到我的实际表格视图时,索引大小很小,它只显示几个字母。如何停止调整大小?

【问题讨论】:

    标签: iphone uitableview iphone-sdk-3.0


    【解决方案1】:

    您必须在 viewController.m 文件中放置适当的 UITableView 委托方法。

    例如,我放置了以下代码。

    请仔细阅读cmets。

    #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;
    }
    

    【讨论】:

      最近更新 更多