2010-03-27 11 views
6

Do tej pory tworzyłem niestandardowe końcówki, aby moja komórka była taka, jak chciałem, ale tym razem wysokość komórki zmieni się z jednej na drugą, tak że nie mogę utworzyć Stalówka o stałej wielkości.Widok tabeli z komórką niestandardową (programowo)

Postanowiłem więc stworzyć programowo ... Czy droga jest poniżej dobrej drogi, aby to osiągnąć?

// 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; 
} 

lub .. czy coś tu brakuje? Przyczyna tej pory nie wydaje się do pracy;)

Dzięki

Gotye.

Odpowiedz

0

nowych linków dla niestandardowego UITableViewCell programowo Apple Documentation UITableViewCell

+0

Należy pamiętać, że [odpowiedzi dotyczące tylko łącza] (http://meta.stackoverflow.com/tags/link-only-answers/info) są odradzane, odpowiedzi SO powinny być punktem końcowym wyszukiwania rozwiązania (vs. jeszcze jeden przystanek referencji, które z czasem zanikają). Proszę rozważyć dodanie samodzielnego streszczenia tutaj, zachowując odnośnik jako odniesienie – kleopatra

0

Po co tworzyć etykiety, gdy nie jest to konieczne? Użyj etykiety 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; 
} 
Powiązane problemy