2012-04-28 20 views
5

में कोशिकाओं को ओवरलैप करता है I एक कस्टम आईओएस तालिका शीर्षलेख बनाने की कोशिश कर रहा है। मेरे हेडर 30px लंबे हैं और मैं उन्हें बनाने के लिए इस कोड का उपयोग कर रहा:कस्टम हेडर समूह

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section]; 
    if (sectionTitle == nil) { 
     return nil; 
    } 

    // Create label with section title 
    UILabel *label = [[UILabel alloc] init] ; 
    label.frame = CGRectMake(0, 0, 140, 30); 
    label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"header_gradient.png"]]; 
    label.textColor = [UIColor whiteColor]; 
    label.shadowColor = [UIColor whiteColor]; 
    label.shadowOffset = CGSizeMake(0.0, 1.0); 
    label.font = [UIFont boldSystemFontOfSize:12]; 
    label.text = sectionTitle; 

    // Create header view and add label as a subview 
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 30)]; 
    [view addSubview:label]; 

    return view; 
} 

- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section { 
    return 30; 
} 

यह लगभग काम करता है, लेकिन मेरे हेडर उन्हें नीचे कोशिकाओं/हेडर के साथ colide करने लगते हैं:

custom headers

कर सकते हैं कोई भी मुझे हेडर को साफ करने के लिए सही दिशा में इंगित करता है? आपके पास

:

- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section { 

यह होना चाहिए:

अग्रिम धन्यवाद

उत्तर

14

में आप भूल रहे हैं एक [स्पेस]

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
+0

यह वास्तव में होना चाहिए '- (CGFloat) तालिका दृश्य: (UITableView *) तालिका देखें ऊंचाईफॉरहेडर इनसेक्शन: (एनएसआईएनटेगर) सेक्शन ' – omz

+0

सही। सही घोषणा निम्नानुसार है (दस्तावेज़ों से): - (CGFloat) तालिका दृश्य: (UITableView *) तालिका दृश्य देखेंफॉरहेडर इनसेक्शन: (एनएसआईएनटेगर) सेक्शन - यदि आप नज़दीक ध्यान दे रहे हैं, तो तालिका दृश्य और ऊंचाई के बीच एक [स्पेस] गायब है ForHeaderInSection .. पूरी तरह से याद किया कि पहली बार, इसलिए मुझे लगता है कि ऊंट का मामला बंद क्यों था। मैंने जवाब अपडेट कर लिया है। पकड़ने के लिए धन्यवाद! –

+0

मदद के लिए धन्यवाद ... मैं यह जानकर पागल हो रहा था कि वह क्यों काम नहीं कर रहा था! – akhalsa

संबंधित मुद्दे