自定义 UITableViewCell 不访问方法

Custom UITableViewCell not accessing methods

我有一个自定义 table 视图单元格(名为 MimoCell),它有一个准备单元格的方法,如标题、副标题、图像和内容。

当我尝试通过传递它应该接收的 object 来访问此方法时,我收到一个无法识别的选择器发送到实例错误。这里的复杂之处在于我通过引用传递了这个 object,我怀疑这是导致错误的原因。 这是单元格

MimoCell.h

 #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

#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];
}

这就是我处理它的地方

- (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 object...

如果您想将自定义笔尖加载到单元格,请在您的 viewDidLoad 方法

中使用它
 UINib *nib = [UINib nibWithNibName:@"MimoCell" bundle:nil];
 [tableViewName registerNib:nib forCellReuseIdentifier:@"MimoCell"];

我想这就是你所缺少的。

好的,我找到问题了。正如我们所见,cellForRowAtIndexPath: 上的单元格 class 确实来自我的 MimoCell class。但错误是生成 UITableCell class 错误。这告诉我在某个地方,我的单元格是一个简单的 UITableCell。

这是故事板。

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