English 中文(简体)
uitableview——习俗图像在电池中保持负荷。
原标题:uitableview - custom images keep loading in cell.contentView

缩略语 我在加入cell.contentView。 问题在于,当囚室从屏幕上排出时,它又把同样的形象提升到前面。 直到我获得一个非常顽固的模糊形象,这种情况就持续发生。

您是否必须删除您在<密码>阁下上添加的任何图像观点? 如果是的话,如果是这样,那么你会采取什么方法?

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

    static NSString *CellIdentifier = @"CellIdentifier";

    MyTableCell *cell = (MyTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpg"]];

    imageView.center = CGPointMake(310, 48);
    [cell.contentView addSubview:imageView];
    [imageView release];
    return cell;
}
最佳回答

如果你不想保持形象 在你的囚室里,如果(细胞=nil)栏内,你必须做所有定制,否则每增加一次电池循环。 在使用电池回收时,你总是想把对你所有的囚室都一致的任何东西都留在该区,以便他们只得到一次添加。

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

    static NSString *CellIdentifier = @"CellIdentifier";

    MyTableCell *cell = (MyTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

        //Add custom objects to the cell in here!
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpg"]];

        imageView.center = CGPointMake(310, 48);
        [cell.contentView addSubview:imageView];
        [imageView release];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    return cell;
}
问题回答

如果每个囚室需要不同的形象,你可以尝试这样的东西:

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

    static NSString *CellIdentifier = @"CellIdentifier";
    static const int ImageViewTag = 1234; //any integer constant

    MyTableCell *cell = (MyTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIImageView *imageView;
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

        //Add custom objects to the cell in here!
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, imgWidth, imgHeight)];

        imageView.center = CGPointMake(310, 48);
        imageView.tag = ImageViewTag;
        [cell.contentView addSubview:imageView];
        [imageView release];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    else
    {
        imageView = [cell viewWithTag:ImageViewTag];
    }
    imageView.image = yourUIImageForThisCell;

    return cell;
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签