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

标签 objective-c ios uitableview

作为带有单个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/

相关文章:

objective-c - iOS 5.1 在后台停止应用程序

android - IBM Worklight 6.1 - 如何检查连接类型?

ios - 如何自定义 UITableview 的右边框、上边框和下边框?

ios - 如何跟踪使用 NSIndexPath 选择的单元格?

iphone - 分组 UITableView 中第一个和最后一个单元格的自定义圆角

ios - Xcode TARGET_OS_IPHONE 似乎很困惑,错误或配置错误?

objective-c - 更改导航项的颜色

ios - while 部分 do-while 语句跳过

ios - CollectionView ItemHeight 比 Collectionview 高度大

objective-c - 符号化 iPad 崩溃日志后回溯仍然不可读