2013-07-02 2 views
1

Почему мой UIView (созданный ниже) не отображается в UITableViewHeader, к которому я пытаюсь его добавить?UIView не отображается в заголовке UITableView

UIView *view = [[UIView alloc] initWithFrame: CGRectMake (20, 20, 400, 400)]; 
searchBar = (UISearchBar *)self.tableView.tableHeaderView; 
[searchBar.subviews objectAtIndex:0] removeFromSuperview]; 
searchBar.backgroundColor = [UIColor clearColor]; 
[view addSubview:searchBar]; 
self.tableView.tableHeaderView = nil; 
view.backgroundColor = [UIColor redColor]; 

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width, 60)]; 
label.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:.35]; 
label.shadowOffset = CGSizeMake(0, -1.0); 
label.text = @"188 People"; 
label.textColor = [UIColor grayColor]; 
label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0]; 
label.backgroundColor = [UIColor clearColor]; 
[view addSubview:label]; 

self.tableView.tableHeaderView = view; 
+0

ты добавив свой UIView к главному виду ViewController? – ApolloSoftware

+1

[self.view addSubview: view]; в конце ... – lakesh

+1

@lakesh Посмотрите на последнюю строку опубликованного кода. – rmaddy

ответ

-1
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *view = [[UIView alloc] initWithFrame: CGRectMake (20, 20, 400, 400)]; 
    searchBar = (UISearchBar *)self.tableView.tableHeaderView; 
    [searchBar.subviews objectAtIndex:0] removeFromSuperview]; 
    searchBar.backgroundColor = [UIColor clearColor]; 
    [view addSubview:searchBar]; 
    view.backgroundColor = [UIColor redColor]; 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width, 60)]; 
    label.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:.35]; 
    label.shadowOffset = CGSizeMake(0, -1.0); 
    label.text = @"188 People"; 
    label.textColor = [UIColor grayColor]; 
    label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0]; 
    label.backgroundColor = [UIColor clearColor]; 
    [view addSubview:label]; 

    return view;//Please note the header will look the same for each section. You can add a switch or if/else to augment this 
} 

-В примечание стороны, если вы планируете использовать метку здесь, чтобы задать текст для заголовка, я предлагаю смотреть на следующие методы:

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; 
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; 
+1

Прочтите исходный код. Речь идет о представлении заголовка для таблицы, а не о заголовке раздела. – rmaddy

+0

Заголовок заголовка или заголовок таблицы, что бы это ни было, это перестало работать на iOS7 ... Кто-нибудь знает какое-либо решение? – mindbomb

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