문제

다음 코드가있었습니다.

- (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;
}
.

그러나 셀의 ImageView를 보지 못했습니다.내가 뭘 잘못하고 있니?

도움이 되었습니까?

해결책

1) URL로 이미지 설정은 iOS 메소드가 아닙니다.그것은 뭔가 사용자 정의이며 문제 일 수 있습니다.그러나 당신이 게시 할 때까지 그것을 도울 수 없습니다.

2) Cell.ImageView가 "setFrame"을 무시할 것으로 생각합니다.이미지를 사용하여 내 테이블 셀에서 일할 수 없습니다.항상 기본적으로 이미지의 너비로 표시됩니다.

3) 일반적으로 셀을 사용하여 이미지를 설정합니다. image= your_image.ImageView는 readOnly이며 이미지보기 프레임은 비공개입니다.

4) 나는 당신이 자신의 맞춤 셀을 만들어야 할 것이라고 생각합니다.

다른 팁

sdimageCache 와도 동일한 문제가 있습니다.내 솔루션은 원하는 프레임 크기로 자리 표시 자 이미지를 넣는 것입니다.

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

자리 표시자를 사용한 방법의 사용은이를 수정합니다.

[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]];
.

방법

메소드의 끝에서 return cell를 입력해야합니다

- (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;
}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top