2011-01-28 16 views
1

UILocalizedIndexedCollat​​ionを使用すると、アルファベットに基づいてセクションインデックスを作成する方法があります。これはかなり簡単で簡単です。 12時間の時計に基づいてセクションインデックスを作成する方法はありますか? "HH:mm a"を使用し、それをセクションヘッダーとして使用するようにします。セクションは12時間形式でインデックスされます

Sagos

答えて

3

sectionIndexTitlesForTableViewを実装:データソースのヘッダーを返すこと。

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 
    return [NSArray arrayWithObjects:@"12:00 AM", @"01:00 AM", ..., @"11:00 PM", nil]; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 24; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    switch(section) { 
     case 0: //12:00 AM 
      ... 
    } 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    switch(indexPath.section) { 
     case 0: //12:00 AM 
      ... 
    } 
} 
+0

私はファイルを解析してDBに格納してからtableviewを作成していますが、numberOfSectionsに静的な数値を使用しないことがあります。しかし、それ以外にも、私の質問に感謝してくれてありがとう。 – lifemoveson

関連する問題