2010-10-05 20 views
7

मुझे गतिशील रूप से आबादी वाले UIViewTable के ऊपर तुरंत एक बटन डालना होगा। यह सही प्रथम कक्ष (पंक्ति 0) पॉप्युलेट नहीं, बल्कि हेडर क्षेत्र का उपयोग करने लगता है, इसलिए मैं UITableViewDelegate विधि का उपयोग प्रोग्राम के रूप में एक UIView एक UIButton युक्त बनाने के लिए: के रूप में नीचे, दर्शायाUITableView शीर्षलेख के शीर्षलेख में UIButton जोड़ना

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{   
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 44)] autorelease]; // x,y,width,height 

    UIButton *reportButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    reportButton.frame = CGRectMake(80.0, 0, 160.0, 40.0); // x,y,width,height 
    [reportButton setTitle:@"rep" forState:UIControlStateNormal]; 
    [reportButton addTarget:self 
        action:@selector(buttonPressed:) 
      forControlEvents:UIControlEventTouchDown];   

    [headerView addSubview:reportButton]; 
    return headerView;  
} 

हालांकि, बटन को आवश्यक स्थान नहीं दिया गया है (मुझे उम्मीद है कि हेडर की ऊंचाई 44 तर्क का पालन करेगी)।

यहां क्या गलत है? मुझे यह जोड़ना चाहिए कि UITableView एक अलग XIB- फ़ाइल में बनाया गया है।

alt text

उत्तर

14

आप भी अपनी तालिका दृश्य प्रतिनिधि पर tableView:heightForHeaderInSection: को लागू करने की है।

+0

ऐसा नहीं था। धन्यवाद। – maralbjo

7

क्या आपने - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section लागू किया है?

+2

बहुत बुरा मैं केवल एक जवाब पुरस्कृत कर सकता हूं। धन्यवाद। – maralbjo

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