Can't connect IBOutlets for custom UITableViewCell

I've got a problem trying to create a custom tableview cell for my iPhone app in Xcode 4. I've created the .h and .m files, created IBOutlets for all of the subviews that should be present inside the cell, and dragged the actual controls onto the cell's XIB file in Interface Builder. However, I can't figure out how to connect the outlets to the IB controls. Every tutorial I read says to control-drag from the TableViewCell object in the objects list to the subviews, but when I do that my IBOutlets are not listed in the popup window. The only outlets that are available are 'acccessoryView', 'backgroundView', 'editingAccessoryView' and 'backgroundSelectedView'. Shouldn't I also be seeing my own IBOutlets in that list as well? Or am I not following the correct procedure? (I'm pretty new to iPhone development).

Here is the code I'm using for the custom cell class:

.h :

//
//  RecommendationCell.h
//  Tuneplug
//
//  Created by Bill Labus on 6/21/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface RecommendationCell : UITableViewCell {
    UIImageView *artwork;
}

@property (nonatomic, retain) UIImageView *artwork;

@end

.m :

//
//  RecommendationCell.m
//  Tuneplug
//
//  Created by Bill Labus on 6/21/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RecommendationCell.h"

@implementation RecommendationCell

@synthesize artwork;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [super dealloc];
}

@end

(Note that I reduced the subviews to just the 'artwork' image view for now, to simplify figuring it out). Thanks for any help!

Answers


Unless I'm misunderstanding:

Try adding the IBOutlet tag.

IBOutlet UIImageView *artwork;

and

@property (nonatomic, retain) IBOutlet UIImageView *artwork;

This tag is a #define within Xcode that tells Interface Builder to recognize your code.


You have to set the Class Identity of the table view cell in Interface Builder to your custom class, even if the .xib file is named the same as your custom class you still need to explicitly mention that File's Owner is an object of type RecommendationCell.

The other issue (mentioned by Patrick) is that you should declare an IBOutlet in your .h on the @property declaration, not the instance variable, like so:

UIImageView *artwork;

@property (nonatomic, retain) IBOutlet UIImageView *artwork;

Wanted to update since I came across this recently. In xcode 7.1.1 you can't drag from the file's owner like you usually can for UIViewController xib's.

Go to the .xib file for your custom UITableViewCell in interface builder.

This is hard to explain, so I've included an image, even with it I'm not sure I'm really explaining this well, but hopefully it helps. Or at least if I come across it again I'll know what I'm talking about.

Right Click on the custom uitableviewcell containing your UILabels or UIImage etc

This will bring up a menu listing all of your IBOutlets and objects contained within your custom uitableviewcell. Put your mouse over the empty circle on the right and ctrl-click-drag to your object.


Need Your Help

What is xcrun cache directory?

xcrun

Where is xcrun cache stored? Also does anyone know how to use xcrun command to clean cache?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.