2012-03-22 16 views
10

मुझे अपने UITableView प्रोग्रामेटिक रूप से एक UITableViewCell के लिए ऊंचाई सेट करने की आवश्यकता है। मैं यह कैसे कर सकता हूँ?एकल UITableViewCell के लिए प्रोग्रामेटिक रूप से सेट करें?

मुझे इस सेल को 150 पिक्सेल ऊंचा होने की आवश्यकता है और अन्य सभी अपनी डिफ़ॉल्ट 44 पिक्सल ऊंचाई पर रह सकते हैं।

धन्यवाद।

उत्तर

42

UITableViewCell ऊंचाई के लिए एक प्रतिनिधि समारोह है।

यहाँ आप उस विशेष सेल के indexPath निर्धारित करें और अपने ऊंचाई लौट यह

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(indexPath.section == yourSection && indexPath.row == yourRow) { 
     return 150.0; 
    } 
    // "Else" 
    return someDefaultHeight; 
} 
2
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

आप इस विधि के साथ एक विशिष्ट सूचकांक पथ पर सेल के लिए मूल्य निर्धारित कर सकते हैं, और अन्य कोशिकाओं के लिए एक डिफ़ॉल्ट मान।

7

तुम्हें पता करना होगा, या यह पता लगाने क्या सेल सूचकांक आप लम्बे एक बनाने के लिए चाहते हैं के लिए। इसे अपना पहला सेल कहें।

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (indexPath.row == 0) { //change 0 to whatever cell index you want taller 
     return 150; 
    } 
    else { 
     return 44; 
    } 
} 
3

स्विफ्ट उत्तर

जो अनुभाग निर्दिष्ट करें और पंक्ति आप बदलना चाहते हैं heightForRowAtIndexPath विधि में (गिनती याद 0 पर शुरू होता है, नहीं 1)।

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{ 
    if indexPath.section == 0 && indexPath.row == 0{ 
     return 150 
    } 
    return 44.0 
} 
संबंधित मुद्दे