2009-06-15 4 views
0

У меня есть UITableView, и в нем есть разные разделы - слова, начинающиеся с буквы «А», перейдите в раздел «А». Слова, начинающиеся с буквы «В», переходят в раздел «В» и т. Д.Как сделать заголовки разделов на нескольких языках

Вот мой код:

-(void) populateTable { 
    if (tableDataArray) 
    { 
     [tableDataArray removeAllObjects]; 
    } 

    for (int i = 0; i <= 27; i++) 
    { 
     NSMutableArray *words_in_section = [ [NSMutableArray alloc] init]; 
     [tableDataArray addObject: words_in_section]; 
     [words_in_section release]; 
    } 

    int cur_section; 
    int cur_word_id; 

    //First section, without title 
    while ((cur_word_id = [ [WordsDatabase sharedWordsDatabase] getNextWordToEditIDABC]) != -1) 
    { 
     NSMutableArray *temp_array = [tableDataArray objectAtIndex: 0]; 
     [temp_array addObject: [NSNumber numberWithInt: cur_word_id] ]; 
     [tableDataArray replaceObjectAtIndex: 0 withObject:temp_array]; 
    } 

    //All other sections 
    while ((cur_word_id = [ [WordsDatabase sharedWordsDatabase] getNextWordIDABC]) != -1) 
    { 
     cur_section = toupper([ [ [WordsDatabase sharedWordsDatabase] getWordAtID:cur_word_id] characterAtIndex:0 ]) - 'A'; 
     if (cur_section < 0) cur_section = 27; 
     else if (cur_section > 27) cur_section = 27; 
     else cur_section++; 

     NSMutableArray *temp_array = [tableDataArray objectAtIndex:cur_section]; 
     [temp_array addObject: [NSNumber numberWithInt: cur_word_id] ]; 
     [tableDataArray replaceObjectAtIndex:cur_section withObject:temp_array]; 
    } 

    [mainTableView reloadData]; 
} 

Я хочу, чтобы достичь чего-то похожее на музыкальный список IPOD - есть песни, которые отсортированы в алфавитном порядке и наиболее интересное, что список поддерживает все другие языки, кроме английский.

Как я могу это достичь? Мой код работает только с английскими буквами, а все остальные буквы присваиваются последнему разделу.

Вот как я поставил точку заголовка:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    if ([ [tableDataArray objectAtIndex: section] count] == 0) return nil; 

    UITableViewCell *header_view = [ [ [UIView alloc] initWithFrame: CGRectMake(0, 0, 300, 20)] autorelease]; 

    header_view.backgroundColor = [UIColor orangeColor]; 

    UILabel *captionLabel = [ [ [UILabel alloc] initWithFrame: CGRectMake(10, 0, 290, 20)] autorelease]; 
    captionLabel.backgroundColor = [UIColor orangeColor]; 

    [header_view addSubview: captionLabel]; 

    if (section == 0) 
    { 
     return nil; 
    } else if (section >= 27) 
    { 
     captionLabel.text = @"#"; 
     return header_view; 
    } else 
    { 
     captionLabel.text = [NSString stringWithFormat: @"%c", section + 'A' - 1]; 
     return header_view; 
    } 

    return nil; 
} 

Как я могу добавить к моей коде поддержке различных языков?

Заранее спасибо.

ответ

0

Различные языки имеют разные соглашения о том, как классифицировать слова. Например, на японском языке вам, вероятно, понадобится либо 10 разделов (для каждой строки таблицы катаканы), либо 50 или около того, чтобы представить каждую начальную катакану. Я предполагаю, что для каждого языка вам нужно будет соблюдать особые правила.

Смежные вопросы