2012-05-22 20 views
6

Vì vậy, tôi đã có đoạn mã sau:UITableViewCell IMAGExem không hiển thị

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *CellIdentifier = @"FriendsCell"; 

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row]; 

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

    [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)]; 
    [cell.textLabel setText:fd.name_]; 

    return cell; 
} 

Tuy nhiên, tôi không nhìn thấy những IMAGExem trong tế bào. Tôi đang làm gì sai?

+1

chúng ta hãy xem phương pháp -setImageWithURL bạn – shabbirv

+1

Cùng với nhìn thấy 'setImageWithURL: ', bạn có chắc rằng **' fd.imageUrl_' ** không phải là con số không? – WrightsCS

+0

có url hợp lệ và không phải là số không – adit

Trả lời

3

1) Set hình ảnh với URL không phải là một phương pháp iOS. Đó là một cái gì đó tùy chỉnh và đó có thể là vấn đề. Nhưng cho đến khi bạn xuất bản nó không thể giúp đỡ ở đó.

2) Tôi nghĩ cell.imageView sẽ bỏ qua "setFrame". Tôi không thể làm điều đó để làm việc trong bất kỳ tế bào bảng nào của tôi bằng cách sử dụng một hình ảnh. Nó luôn luôn dường như mặc định chiều rộng của hình ảnh.

3) Thông thường bạn đặt hình ảnh bằng cách sử dụng cell.imageView.image = your_Image. ImageView là READONLY và có lẽ khung ImageView là riêng tư.

4) Tôi nghĩ bạn sẽ cần phải tạo một ô tùy chỉnh của riêng bạn.

2

bạn cần phải return cell ở phần cuối của phương pháp

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *CellIdentifier = @"FriendsCell"; 

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row]; 

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

    [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)]; 
    [cell.textLabel setText:fd.name_]; 
    return cell; 
} 
+0

Tôi đã làm điều đó thực sự .. Tôi chỉ cần cắt nó đi – adit

4

Tôi cũng gặp vấn đề tương tự với SDImageCache. Giải pháp của tôi là đặt một hình ảnh giữ chỗ với kích thước khung hình mà bạn muốn.

UIImage *placeholder = [UIImage imageNamed:@"some_image.png"]; 
[cell.imageView setImage:placeholder]; 
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
3

Cách sử dụng phương thức có trình giữ chỗ sẽ khắc phục.

[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]]; 
Các vấn đề liên quan