私はそれを検索しようとしましたが、今のところ答えが見つからないようです。
現在、プロトタイプ セルを使用してデータを動的に入力しています。
日付に従ってセルを動的にグループ化する必要があります。
2001 年 1 月 1 日に 3 つの行があるとしましょう。2001 年 2 月 1 日の時点で、5 行あります。セルを動的にグループ化する方法を示すガイドまたはサンプルが見つからないようです。以下は私のコードの一部です。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [someArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
IssuesViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[IssuesViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
currentSomething = [[Something alloc] init];
currentSomething = [somethingDiscovered objectAtIndex:indexPath.row];
cell.typeLabel.text = currentSomething.type;
cell.titleLabel.text = currentSomething.title;
cell.begDateLabel.text = currentSomething.begDate;
return cell;
}
2013 年 8 月 23 日更新:
動的にグループ化できるようになりましたが、セルの正しいデータを表示する際に問題が発生しています。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return return [someDate count]; //someDate is an array that stores dates
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
// set title of section here
return [someDate objectAtIndex:section]; //set the title of each section as a date
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [[someIssues objectAtIndex:section] count]; //some issues hold data to be displayed in the cell.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
IssuesViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[IssuesViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
currentSomething = [[Something alloc] init];
currentSomething = [somethingDiscovered objectAtIndex:indexPath.row];
cell.typeLabel.text = currentSomething.type;
cell.titleLabel.text = currentSomething.title;
cell.begDateLabel.text = currentSomething.begDate;
return cell;
}
たとえば、オブジェクト A、B、C、D、E、F、G、H、I、J、K。そして、4 つのセクションがあります。section[0] は A、B、C、D、E、F、G を表示するとします。 Section[3] は、H、I、J、K を表示するとします。
しかし今、セクション[0]にはA、B、C、D、E、F、Gしか表示されません。A、B、C、D、セクション [3]。手伝ってください。
解決:
someIssue = [[someIssues objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];