2016-01-19 4 views
1

Здесь я установил описание, цену, а также местоположение от-до, но не смог установить дату и время, как показано на рисунке выше. Формат сталкивается с некоторой проблемой, чтобы установить дату в одном заголовке и время в другом. Если какая-либо ссылка, которая показывает, как устанавливать вложенные заголовки, мне очень поможет.UItableView: Вложенные секции заголовка

Заранее спасибо.

enter image description here

+0

Вы пытаетесь добавить заголовок с датой и временем в 2 строках с некоторым разделителем между ними, как показано на изображении? –

+0

Да. Как показано на рисунке m, невозможно добавить разделитель между ними. –

ответ

0

Да, как показано на рисунке, не в состоянии добавить разделитель в between.I также попробовал этот

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

}

но перед проблемой, что вид дата получаю тревожить время прокрутка стола.

-1

Создайте файл xib, который имеет UIView и метки внутри него, как показано на прилагаемом скриншоте. xib with seperator

  1. Иметь исходные файлы с именем CustomHeader, который является подклассом UIView.
  2. Составьте свой xib-просмотр с помощью CustomHeader класса.
  3. Сгенерировать IBOutlets для ярлыков, добавленных в xib.

В вашем ViewControllerviewForHeaderInSection методе

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
NSArray * bundleArray = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil]; 
CustomUIClass * view = (CustomUIClass *) [bundleArray objectAtIndex:0]; 
return view; 

}

переопределять Также heightForHeaderInSection

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
return 69.0f; 

}

здесь '69' является высота хх б. Теперь ваш табличный вид выглядит как прикрепленный скриншот.

Customized tableview header

Как это вы можете настроить свой заголовок в соответствии с вашими требованиями.

Смежные вопросы