我有一个定制的表视图单元格(名为MimoCell),它有一个准备单元格的方法,比如标题、字幕、图像等等。
当我试图通过传递它应该接收的对象来访问这个方法时,我会得到一个无法识别的选择器发送到实例错误。这里复杂的事情是因为我通过引用传递这个对象,我怀疑这是导致错误的原因。这是牢房
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对象.
发布于 2015-03-24 17:54:10
好的,我发现了问题。正如我们所看到的,cellForRowAtIndexPath:上的单元格类确实来自于我的MimoCell类。但是这个错误产生了一个UITableCell类错误。这告诉我,在某个地方,我的手机是一个简单的UITableCell。
IT是故事板。
我没有把课设置在故事板单元格上。
发布于 2015-03-24 15:38:15
如果要将自定义nib加载到单元格,请在viewDidLoad方法中使用此方法
UINib *nib = [UINib nibWithNibName:@"MimoCell" bundle:nil];
[tableViewName registerNib:nib forCellReuseIdentifier:@"MimoCell"];我想这就是你错过的。
https://stackoverflow.com/questions/29236140
复制相似问题