【问题标题】:Puzzling UIImageView behavior in a UITableViewCellUITableViewCell 中令人费解的 UIImageView 行为
【发布时间】:2011-08-22 23:47:19
【问题描述】:

我目前在我的 UITableViewCell 中设置 UIImageView,如下所示:

// in cellForRowAtIndexPath method
[cell.imageView initWithImage:[UIImage imageNamed:@"myImage.png"]];

但是 UITableViewCell 上的 imageView 属性是readonly。上面的代码有效,但我不明白为什么有什么想法

【问题讨论】:

    标签: ios uitableview properties uiimageview uiimage


    【解决方案1】:

    除非您自己创建对象,否则永远不要调用-init...。单元格创建自己的图像视图(这就是为什么它是只读的);您可以简单地使用cell.imageView.image = [UIImage...]; 设置图像。

    【讨论】:

    • 可能只是-[UIImageView initWithImage:] 没有检查是否已经初始化,它有设置图像的行为。 (你没有遇到readonly 限定符的问题,因为你没有尝试设置单元格的图像视图——你只是向它发送一条消息。)然而,这样做从来都不是好习惯重新初始化一个对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 2018-07-02
    • 2020-06-19
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    相关资源
    最近更新 更多