как управлять индексом, отображаемым в табличном представлении - PullRequest
0 голосов
/ 13 апреля 2010

Я могу показать индекс справа, похожий на просмотр песен на iPod. Во время поиска индексная полоска сворачивается автоматически. И когда я возвращаюсь к своему фактическому виду таблицы, размер индекса невелик, и он отображает только несколько алфавитов. Как остановить изменение размера этого?

1 Ответ

2 голосов
/ 13 апреля 2010

Вы должны поместить надлежащие методы делегата UITableView в ваш файл viewController.m.

например, я разместил следующий код.

Пожалуйста, внимательно прочитайте комментарии.

#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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...