2010-03-27 20 views
6

अब तक, मैं अपने सेल को वांछित करने के लिए कस्टम निब्स बनाना चाहता था, लेकिन इस बार, सेल की ऊंचाई एक से दूसरे में बदल जाएगी ताकि मैं कोई नहीं बना सकूं निश्चित आकार के सेल की नीब।कस्टम सेल (प्रोग्रामेटिक रूप से) के साथ तालिका दृश्य

इसलिए मैंने इसे प्रोग्रामेटिक रूप से बनाने का निर्णय लिया ... क्या इसे हासिल करने के अच्छे तरीके से नीचे है?

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     UILabel *pseudoAndDate = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,20.0)]; 
     [pseudoAndDate setTag:1]; 
     [cell addSubview:pseudoAndDate]; 
     [pseudoAndDate release]; 
    } 

    CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]]; 

    UILabel *label = (UILabel *)[cell viewWithTag:1]; 
    [label setText:[NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date]]; 

    return cell; 
} 

या .. क्या मुझे यहां कुछ याद आ रही है? अब तक यह काम करने के लिए प्रतीत नहीं होता कारण;)

धन्यवाद,

Gotye।

उत्तर

0

न्यू लिंक कस्टम UITableViewCell प्रोग्रामेटिक रूप से Apple Documentation UITableViewCell

+0

ध्यान दें कि [केवल-लिंक उत्तर] (http://meta.stackoverflow.com/tags/link-only-answers/info) निराश हैं, SO उत्तर समाधान के लिए खोज का अंत बिंदु होना चाहिए (बनाम। फिर भी संदर्भों का एक और स्टॉपओवर, जो समय के साथ पुराना हो जाता है)। लिंक को संदर्भ के रूप में रखते हुए, यहां स्टैंड-अलोन सारांश जोड़ना पर विचार करें – kleopatra

0

जब आपको आवश्यकता नहीं है तो लेबल क्यों बनाएं? UITableViewCell के लेबल का उपयोग करें।

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]]; 

    cell.textLabel.text = [NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date]; 

    return cell; 
} 
0

यदि आपका समस्या यह है कि ऊंचाई सेल आप विधि का उपयोग कर सकते हैं सेल से लेकर है:

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath:

UITableViewDelagate से इसे प्राप्त करने के