加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 无法为自定义UITableViewCell连接IBOutlets

发布时间:2020-12-14 18:05:11 所属栏目:百科 来源:网络整理
导读:我在 Xcode 4中为我的iPhone应用程序创建自定义tableview单元时遇到了问题.我创建了.h和.m文件,为单元格内应存在的所有子视图创建了IBOutlets,并进行了拖动Interface Builder中对单元格的XIB文件的实际控制.但是,我无法弄清楚如何将插座连接到IB控件.我读过
我在 Xcode 4中为我的iPhone应用程序创建自定义tableview单元时遇到了问题.我创建了.h和.m文件,为单元格内应存在的所有子视图创建了IBOutlets,并进行了拖动Interface Builder中对单元格的XIB文件的实际控制.但是,我无法弄清楚如何将插座连接到IB控件.我读过的每个教程都说控制 – 从对象列表中的TableViewCell对象拖动到子视图,但是当我这样做时,我的IBOutlets没有列在弹出窗口中.唯一可用的插座是’acccessoryView’,’backgroundView’,’editingAccessoryView’和’backgroundSelectedView’.我不也应该在该列表中看到自己的IBOutlets吗?或者我没有遵循正确的程序? (我对iPhone开发很新).

这是我用于自定义单元类的代码:

.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

(请注意,我现在将子视图缩小为“图稿”图像视图,以简化计算).谢谢你的帮助!

解决方法

除非我误解:

尝试添加IBOutlet标记.

IBOutlet UIImageView *artwork;

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

此标记是Xcode中的#define,它告诉Interface Builder识别您的代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读