ios - 用户界面 TableView : Nested Header sections

标签 ios objective-c nsdate nsdateformatter

在这里,我已经设置了描述,价格以及从-到的位置,但无法设置日期和时间,如上图所示。格式面临一些问题,相应地在一个标题中设置日期,在另一个标题中设置时间。如果任何显示如何设置嵌套标题的链接对我有很大帮助。

提前致谢。

enter image description here

最佳答案

是的,如图,中间不能加分隔符,我也试过了

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
NSMutableArray *arrdate=[[NSMutableArray alloc]init];
arrdate=[date1 objectAtIndex:section] ;
NSLog(@"%@",arrdate);
NSMutableArray *arrtime=[[NSMutableArray alloc]init];
arrtime=[time objectAtIndex:section];
NSString *strvalue=[arrdate objectAtIndex:0];
UIView *view;

if([strvalue isEqualToString: strcheck])
{
    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 15)];
    /* Create custom view to display section header... */
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 15)];
    [label1 setFont:[UIFont boldSystemFontOfSize:12]];
    strcheck=[arrdate objectAtIndex:0] ;
    NSString *string =[arrtime objectAtIndex:0];
    /* Section header is in 0th index... */
    [label1 setText:string];
    [view addSubview:label1];

}
else{
    /* Create custom view to display section header... */
    view= [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 100)];
    //main time
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 15)];
    [label setFont:[UIFont boldSystemFontOfSize:12]];
    strcheck=[arrdate objectAtIndex:0] ;
    /* Section header is in 0th index... */
    [label setText:strcheck];
    [view addSubview:label];


    //time..
    UILabel *labeltime = [[UILabel alloc] initWithFrame:CGRectMake(10,20, tableView.frame.size.width, 15)];
    [labeltime setFont:[UIFont boldSystemFontOfSize:12]];

    NSString *stringtime =[arrtime objectAtIndex:0];
    /* Section header is in 0th index... */
    [labeltime setText:stringtime];
    [view addSubview:labeltime];
    }
return view;

但在滚动 tableview 时,日期 View 会受到干扰。

关于ios - 用户界面 TableView : Nested Header sections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34870872/

相关文章:

ios - Swift - 如何检查 JSQMessagesViewController 中是否存在两个用户?

ios - 真机上Glance访问IBOutlet时出现WatchKit "unexpectedly found nil while unwrapping an Optional value"

iphone - 在 TableViewCell 上填充

iphone - 为 iOS 创建本地化文件

ios - 在 Swift 中比较时间

ios - 将NSDate转换为Unix时间戳以在字典中使用

ios - 在祖 parent - parent -子女数据模型关系中适当使用 NSCoding

ios - MPMusicPlayerController 没有响应接近 1 的 currentPlaybackRate

objective-c - Xcode 4 内置帮助您自己的文件

ios - 转换 NSString->NSDate?