自定义了一个Cell继承UItableViewCell,在nib文件中拖入一个cell,把identifier改成了和cellForRowAtIndexPath方法里的复用标识符。
问题来了,我运行程序后,拖动cell,程序崩溃。报错-[UIImage isKindOfClass:]: message sent to deallocated instance 0x1d504c70
上代码:ChatCustomCell1.h#import <UIKit/UIKit.h>@interface ChatCustomCell1 : UITableViewCell
{}@property (retain, nonatomic) IBOutlet UIImageView *leftFaceImageView;
@property (retain, nonatomic) IBOutlet UIImageView *rigthFaceImageView;
@property (retain, nonatomic) IBOutlet UIImageView *messageBackImage;
@property (retain, nonatomic) IBOutlet UILabel *leftNameLable;
@property (retain, nonatomic) IBOutlet UILabel *rightNameLable;
@property (retain, nonatomic) IBOutlet UILabel *leftTimeLable;
@property (retain, nonatomic) IBOutlet UILabel *rightTimeLable;
@property (retain, nonatomic) IBOutlet UILabel *messageLable;@end
ChatCustomCell1.m
#import "ChatCustomCell1.h"@implementation ChatCustomCell1
@synthesize leftFaceImageView=_leftFaceImageView;
@synthesize rigthFaceImageView=_rigthFaceImageView;
@synthesize messageBackImage=_messageBackImage;
@synthesize leftNameLable=_leftNameLable;
@synthesize rightNameLable=_rightNameLable;
@synthesize leftTimeLable=_leftTimeLable;
@synthesize rightTimeLable=_rightTimeLable;
@synthesize messageLable=_messageLable;- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated]; // Configure the view for the selected state
}@end
uitableviewcell自定义Cell复用
问题来了,我运行程序后,拖动cell,程序崩溃。报错-[UIImage isKindOfClass:]: message sent to deallocated instance 0x1d504c70
上代码:ChatCustomCell1.h#import <UIKit/UIKit.h>@interface ChatCustomCell1 : UITableViewCell
{}@property (retain, nonatomic) IBOutlet UIImageView *leftFaceImageView;
@property (retain, nonatomic) IBOutlet UIImageView *rigthFaceImageView;
@property (retain, nonatomic) IBOutlet UIImageView *messageBackImage;
@property (retain, nonatomic) IBOutlet UILabel *leftNameLable;
@property (retain, nonatomic) IBOutlet UILabel *rightNameLable;
@property (retain, nonatomic) IBOutlet UILabel *leftTimeLable;
@property (retain, nonatomic) IBOutlet UILabel *rightTimeLable;
@property (retain, nonatomic) IBOutlet UILabel *messageLable;@end
ChatCustomCell1.m
#import "ChatCustomCell1.h"@implementation ChatCustomCell1
@synthesize leftFaceImageView=_leftFaceImageView;
@synthesize rigthFaceImageView=_rigthFaceImageView;
@synthesize messageBackImage=_messageBackImage;
@synthesize leftNameLable=_leftNameLable;
@synthesize rightNameLable=_rightNameLable;
@synthesize leftTimeLable=_leftTimeLable;
@synthesize rightTimeLable=_rightTimeLable;
@synthesize messageLable=_messageLable;- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated]; // Configure the view for the selected state
}@end
uitableviewcell自定义Cell复用
解决方案 »
- iOS中scrollview自动滚动的实现
- iphone 开发,如何隐藏navigationbar????请指教。。。
- 如何实现类似iphone来点效果
- 开发员必备的工具网站,找图标很方便~
- UISplitViewController 的 masterViewController 和 detailViewController 如何通讯?
- 自定义cell,如何设置cell不被选中
- 好几年没有在csdn发帖了,回到这里又回到了上学时代的感觉,现在遇到一点麻烦,希望得到各位大神的帮助,小弟在这感激不尽
- 开发具有导航功能的APP,在不使用第三方接口的情况下应该如何入手?
- 问一下如何彻底清空一个模型
- majava14更新Catalina15时,在安装时一直卡在苹果logo界面
- 继承CCSprite类,初始化就报错
- 苹果可以用什么语言开发?
{
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
static NSString *identifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell*)[tableView dequeueReusableCellWithIdentifier: identifier];
if(cell == nil)
{
printf("在这里cell == nil\n");
[self.cellNib instantiateWithOwner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
}
NSInteger row = [indexPath row];
ChatMessage *chatMessage = (ChatMessage *)[showMessageArray objectAtIndex:row];
cell.message = chatMessage.message; // 设置cell
if (chatMessage.fromMyself)
{
UIImage *image = [UIImage imageNamed:@"online.png"];
cell.leftFaceImage = image;
[image release];
cell.leftTime = chatMessage.messageTime;
UIImage *image1 = [UIImage imageNamed:@"bubule2"];
cell.messageBack = image1;
[image1 release];
AppDelegate *myApp = [[UIApplication sharedApplication] delegate];
cell.leftName = myApp.loginName;
}
else
{
UIImage *image = [UIImage imageNamed:@"online.png"];
cell.rigthFaceImage = image;
[image release];
cell.rightTime = chatMessage.messageTime;
UIImage *image1 = [UIImage imageNamed:@"bubule1"];
cell.messageBack = image1;
[image1 release];
cell.rightName = chatMessage.senderName;
}
return cell;
}
现在知道什么问题了,是复用过后,对队列里的cell内容进行修改导致的问题。但是麻烦有经验的给个建议,我想让这个cell在一种情况下左边显示图片和内容,另一种情况下右边显示。是改控件位置吗?我之前的做法是左右各加一个image,复用的时候就除了崩溃的问题。