UITableViewCell
与单曲中的流行部分一样NSArray
吗?我有一个事件数组,将数据加载到cellForRowAtIndexPath
中,我应该按年事件创建部分。
例如:
2012 年部分
日期:01/01/2012
事件:现场音乐
日期:01/02/2012
事件:现场音乐
部分 2011
日期:01/01/2011
事件:现场音乐
日期:01/02/2011
事件:现场音乐
单元格已经填充,我只怀念划分为部分的部分,创建两个部分(最多两年)。
对不起,我还是有点迷茫,我解决不了,请帮帮我,什么时候考?我会发布我的代码,非常感谢
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//acquisisco la data dell'evento
NSString *dataEv = [[events objectAtIndex:indexPath.row + indexPath.section]DataEvento];
//retrive year ,example 2011, 2012 when test?
NSString *Year = [Utility getPartOfDate:dataEv type:UTLGetYear];
//set image
...
[cell.contentView addSubview:myImg];
//set day
day.text = [Utility getPartOfDate:dataEv type:UTLGetNumberOfDay];;
[cell.contentView addSubview:day];
//set dayOfWeek
...
dayOfWeek.text = [Utility getPartOfDate:dataEv type:UTLGetDayOfWeek];;
[cell.contentView addSubview:dayOfWeek];
//set month
month.text = [Utility getPartOfDate:dataEv type:UTLGetTextMonth];;
[cell.contentView addSubview:month];
//set title
...
lblTitleEvent.text = [[eventi objectAtIndex:indexPath.row + indexPath.section]Artist];
[cell.contentView addSubview:lblTitoloEvento];
//set description event
lblDescEvento.text = [[eventi objectAtIndex:indexPath.row + indexPath.section]Description];
[cell.contentView addSubview:lblDescriptionEvent];
}else{
lblTitleEvent = (UILabel*)[cell.contentView viewWithTag:5];
lblTitleEvent.text = [[events objectAtIndex:indexPath.row + indexPath.section]Artista];
lblDescEvent = (UILabel*)[cell.contentView viewWithTag:6];
lblDescEvent.text = [[events objectAtIndex:indexPath.row + indexPath.section]Description];
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [events count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0){
return @"Section 1";
}
if(section == 1){
return @"Section 2";
}
}