Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a UIImageView inside a custom UITableViewCell Class (Swift)

No matter how I seem to attempt to conquer this beast, it always beats me down. I cannot (without errors) have a UIImageView inside my UITableViewCell class. I've tried connecting it from the storyboard to the code through a referencing outlet with a strong and a weak storage, writing out the code myself, and even doing without the storyboard and creating a UIImageView programmatically. Is this just a bug with Swift? Am I doing something wrong?

Here's a screenshot of my error:

enter image description hereenter image description here

like image 302
Louie Bertoncin Avatar asked Jan 03 '15 04:01

Louie Bertoncin


2 Answers

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

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

like image 114
rakeshbs Avatar answered Nov 02 '22 20:11

rakeshbs


It is not a bug in swift and yes you are doing something wrong. A UITableViewCell class already has certain objects in it which can not be overridden. One of those is imageView. Since the base class of UITableViewCell already has an imageView object you are getting an error since you named your object the same thing. Just change the name to something else that is not part of the base class and it will work. Same thing goes for textLabel, detailTextLabel...etc.

like image 23
Pete42 Avatar answered Nov 02 '22 19:11

Pete42