Create UIImageView inside custom UITableViewCell class (Swift)

No matter how I seem to try to defeat this beast, it always hits me. I cannot (without error) have a UIImageView inside my UITableViewCell class. I tried to connect it from storyboard to code via referencing output with strong and weak storage, writing the code myself and even dispensing with the storyboard and creating a UIImageView programmatically. Is this just a mistake with Swift? Am I doing something wrong?

Here is a screenshot of my error:

enter image description hereenter image description here

+3


source to share


2 answers


The UITableViewCell class already has a property called imageView. This is why you cannot create another property with the same name. Try using an already available image, or instantiate a UIImageView with a different variable name.



For more information refer to the UITableViewCell documentation https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instp/UITableViewCell/imageView

+7


source


This is not a quick mistake and yes, you are doing something wrong. The UITableViewCell class already has certain objects in it that cannot be overridden. One of them is ImageView. Since the base class UITableViewCell already has an imageView object, you are getting an error as you named your object the same. Just change the name to something else that is not part of the base class and it will work. The same goes for textLabel, detailTextLabel ... etc.



+1


source







All Articles