gpt4 book ai didi

objective-c - 如何使用单个NSArray在UITbleViewCell中创建节?

转载 作者:行者123 更新时间:2023-12-01 16:56:16 25 4
gpt4 key购买 nike

作为带有单个UITableViewCellNSArray中的热门部分?
我有一个事件数组,如果我按年事件创建节,则将数据加载到cellForRowAtIndexPath中。

例:

部分2012
日期:2012年1月1日
Activity :现场音乐

日期:2012年1月2日
Activity :现场音乐

部分2011
日期:2011年1月1日
Activity :现场音乐

日期:01/02/2011
Activity :现场音乐

单元格已经填充,我只想念分成几部分的部分,所以要创建两个部分(最多两年)。

对不起,我还是有点困惑,我解决不了,请帮我,什么时候考一年?我将发布我的代码,非常感谢

-(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";
}
}

最佳答案

试试这个

在cell.textlabel.text中:

cell.textlabel.text = [NSString stringWithFormat:@"%@/n%@/n%@",[array1 ObjectAtIndex:row],......];

您也必须将 HightForRow设置为更大的空间

等等

关于objective-c - 如何使用单个NSArray在UITbleViewCell中创建节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11501140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com