2010-03-27 24 views
6

Cho đến nay, tôi đã sử dụng để tạo ra các ngòi tùy chỉnh để tạo ô như tôi muốn nhưng thời gian này, chiều cao của ô sẽ thay đổi từ cái này sang cái khác để tôi không thể tạo kích thước cố định của tế bào nib.Chế độ xem bảng với ô tùy chỉnh (theo lập trình)

Vì vậy, tôi quyết định tạo nó theo chương trình ... Có phải cách dưới đây là cách tốt để đạt được nó?

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

hoặc .. Tôi có thiếu gì đó ở đây không? Nguyên nhân cho đến nay nó dường như không hoạt động;)

Cảm ơn,

Gotye.

Trả lời

0

liên kết mới cho tùy chỉnh UITableViewCell lập trình Apple Documentation UITableViewCell

+0

Lưu ý rằng [câu trả lời chỉ có liên kết] (http://meta.stackoverflow.com/tags/link-only-answers/info) không được khuyến khích, các câu trả lời SO phải là điểm cuối của việc tìm kiếm giải pháp (so với nhưng một điểm dừng khác của tài liệu tham khảo, mà có xu hướng để có được cũ theo thời gian). Vui lòng xem xét thêm bản tóm tắt độc lập tại đây, giữ liên kết dưới dạng tham chiếu – kleopatra

0

Tại sao tạo nhãn khi bạn không cần? Sử dụng nhãn của 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; 
} 
Các vấn đề liên quan