首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义UITableViewCell不访问方法

自定义UITableViewCell不访问方法
EN

Stack Overflow用户
提问于 2015-03-24 15:08:51
回答 2查看 51关注 0票数 0

我有一个定制的表视图单元格(名为MimoCell),它有一个准备单元格的方法,比如标题、字幕、图像等等。

当我试图通过传递它应该接收的对象来访问这个方法时,我会得到一个无法识别的选择器发送到实例错误。这里复杂的事情是因为我通过引用传递这个对象,我怀疑这是导致错误的原因。这是牢房

MimoCell.h

代码语言:javascript
复制
 #import <UIKit/UIKit.h>
#import "Mimo.h"
@interface MimoCell : UITableViewCell

@property (nonatomic)BOOL flagFriendCell;
@property (nonatomic)BOOL flagImageMimo;
@property (nonatomic,strong)UILabel *detailLabel;
@property (nonatomic,strong)UIButton *mimoImageBtn;
@property (nonatomic,strong)UIImage *mimoImage;


-(void)setMimo:(Mimo**)theMimo;

@end

,这是MimoCell.m

代码语言:javascript
复制
#import "MimoCell.h"
#import "currentUser.h"
@implementation MimoCell
{
    Mimo *mimo;
    currentUser *thisUser;
    NSTimer *syncCellTimer;
}
@synthesize detailLabel;
@synthesize flagFriendCell;
@synthesize flagImageMimo;
@synthesize mimoImageBtn;
@synthesize mimoImage;
-(void)setMimo:(Mimo *__autoreleasing *)theMimo{
    mimo = *theMimo;
    if(mimo.flagIsImage)
        flagImageMimo = NO;
    else
        flagImageMimo = YES;

    if([mimo.senderID isEqualToString:thisUser.userID])
        flagFriendCell = NO;
    else
        flagFriendCell = YES;


}



- (void)awakeFromNib {
    // Initialization code
    thisUser = [currentUser instance];
    detailLabel = [[UILabel alloc]initWithFrame:CGRectMake(30.0, 87.0, 200.0, 12)];
    [detailLabel setFont:[UIFont fontWithName:@"Helveltica" size:11]];
    [self.textLabel setTextAlignment:NSTextAlignmentCenter];
    syncCellTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(syncCell) userInfo:nil repeats:YES];
    [syncCellTimer fire];
    mimoImageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
}

这就是我处理它的地方

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"mimoCell";
    MimoCell *cell = (MimoCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){//It's never nil
        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"MimoCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    Mimo *workingMimo = [arrayOfMimos objectAtIndex:indexPath.row];
    [cell setMimo:&workingMimo];//RIGHT HERE I GET THE UNRECOGNIZED SLECTOR ERROR



    return cell;
}

我做错什么了?我真的很想参考MIMO对象.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-24 17:54:10

好的,我发现了问题。正如我们所看到的,cellForRowAtIndexPath:上的单元格类确实来自于我的MimoCell类。但是这个错误产生了一个UITableCell类错误。这告诉我,在某个地方,我的手机是一个简单的UITableCell。

IT是故事板。

我没有把课设置在故事板单元格上。

票数 0
EN

Stack Overflow用户

发布于 2015-03-24 15:38:15

如果要将自定义nib加载到单元格,请在viewDidLoad方法中使用此方法

代码语言:javascript
复制
 UINib *nib = [UINib nibWithNibName:@"MimoCell" bundle:nil];
 [tableViewName registerNib:nib forCellReuseIdentifier:@"MimoCell"];

我想这就是你错过的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29236140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档