2014-01-13 14 views
17

最初のセクションヘッダーが表示されない理由を理解できません。二番目と三番目は上手く見える。私はそれが検索バーのためだと思う。テーブルの最初のセクションヘッダーが表示されないのはなぜですか?

UISearchBar covered by section headerのようにテーブル全体をオフセットしてみましたが、オフセットに気づいていませんでした。

hierarchy of elements

screenshot

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    // create the parent view that will hold header Label 
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)]; 

    // create the label object 
    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 
    headerLabel.frame = CGRectMake(0,0,self.view.frame.size.width,60); 
    UIColor* mainColor = [UIColor colorWithRed:47.0/255 green:168.0/255 blue:228.0/255 alpha:1.0f]; 
    headerLabel.backgroundColor = mainColor; 
    headerLabel.font = [UIFont boldSystemFontOfSize:18]; 

    headerLabel.textAlignment = UITextAlignmentCenter; 

    if(section == 0) 
     headerLabel.text = @"Friends"; 
    if(section == 1) 
     headerLabel.text = @"Second Section Header"; 
    if(section == 2) 
     headerLabel.text = @"Third Section Header"; 
     headerLabel.textColor = [UIColor whiteColor]; 

    [customView addSubview:headerLabel]; 

    return customView;   
} 

- (void) hideSearchBar 
{ 
    self.feedTableView.contentOffset = CGPointMake(0, self.searchBar.frame.size.height); 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 3; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    //Number of rows it should expect should be based on the section 
    NSDictionary *dictionary = [_imageDataArray objectAtIndex:section]; 
    NSArray *array = [dictionary objectForKey:@"data"]; 
    return [array count]; 
} 
+0

そのをあなたは、任意の制約またはいずれかを変更していますか? – Yohan

+0

制約はありません。私がストーリーボードのテーブルの上/外に検索バーを持って来ると、ヘッダーのスペースを見ることができますが、空白です...検索バーがそれほど大丈夫ですか? – jsky

+0

yap私はこれだけのようにヒイラキを設定しました – Yohan

答えて

52

私はここにheightForHeaderInSection
詳細実装されていなかったので、それは表示されませんでした。私のために完璧な作業 in iOS 7 viewForHeaderInSection section is starting from 1 not from 0

+0

私はこれらの "バグ"のためのリンゴが嫌い...以前は問題なかったし、なぜ最初の行だけだったのか... – djleop

+1

戻り値の型がCGFloatであることを確認してください。戻り値の型がNSIntegerの場合、奇妙なバグです。 – kanobius

0

あなたはあなたのコードのバグを得ました。あなたのヘッダーがありますが、それは交換してください60

の高さとy = -60で設定されています。ここでここでこの

// create the parent view that will hold header Label 
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,300,60)]; 

// create the parent view that will hold header Label 
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)]; 

Section 0をスクリーンショットをされます

Section 0 and 1

希望に役立ちます。

+0

ありがとう。それは確かにバグでした。しかし、それを修正しても問題は解決しませんでした。 – jsky

+0

コードの校正をやり直してください。制約が設定されている場合は、それを見てください。実際には私も同じコードを使用しており、うまくいきます。添付の更新画面を私の答えにチェックしてください。 –

関連する問題