简体   繁体   English

如何不使用Custum Cell将Table Cell作为UIImageView使用?

[英]How can i use Table Cell as UIImageView not using Custum Cell?

在我的应用程序中,我必须每3行显示一次图像。我的图像是静态的,应该每3行显示一次。我不想使用UIImageView并将其添加到单元格中,但是如果有任何方法可以直接使用我的图像单元格的属性。我的图像大小为320X87像素。

You would have to create a custom cell for this specific cell, but it will be instanciated once, thanks to reusableCells. 您必须为此特定的单元格创建一个自定义单元格,但是由于reusableCells,它将被实例化一次。 For instance : 例如 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *CellIdentifier = @"TableCell";
    static NSString *ImageIdentifier = @"ImageCell";
    UITableViewCell *cell;

    if (!(indexPath.row % 3))
    {
        cell = [tableView dequeueReusableCellWithIdentifier:ImageIdentifier];
        if (cell == nil)
        {
            cell = [[[MyCustomCell alloc] initWithDelegate:self reuseIdentifier:(NSString *)ImageIdentifier] autorelease];
        }        
    }
    else
    {
        cell = [tableView dequeueReusableCellWithIdentifier:ImageIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithDelegate:self reuseIdentifier:(NSString *)ImageIdentifier] autorelease];
        }   

        // customization of your rows here (title, ...)
    }

    return cell;
}

I don't believe this is possible, as your image is far too large for a standard UITableViewCell. 我认为这是不可能的,因为对于标准的UITableViewCell,您的图像太大了。 You will need to make a custom cell, and then load the appropriate cell in the cellForRowAtIndex method. 您将需要创建一个自定义单元格,然后在cellForRowAtIndex方法中加载适当的单元格。 Don't forget to set the appropriate cellIdentifiers in your code/IB. 不要忘记在代码/ IB中设置适当的cellIdentifiers。

Maybe you could possibly add a UIImageView as a subview of a standard cell's contentView, but this doesn't sound like the best solution to me. 也许您可以将UIImageView添加为标准单元格contentView的子视图,但这听起来并不是我的最佳解决方案。

只需使用适当的委托方法制作一个足够高的单元格,然后将图像视图作为子视图添加到该单元格的contentView属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM