![](/img/trans.png)
[英]ios: Drawing on CALayer in custom UITableViewCell crashes app
[英]ios app crashes when I reload tableView with custom uitableviewcell
我创建了一个自定义表格视图单元格
@interface FixtureTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *teamsVSTextLabel;
@property (weak, nonatomic) IBOutlet UILabel *teamsScoreDetailLabel;
@end
我向服务器发出异步请求以获取数据,并在服务器返回时重新加载表数据。 这是我的
//reload table data when request is over
-(void)finished
{
self.pastFixturesArray = aPastFixture.pastFixturesArray;
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FixtureTableViewCell *cell = (FixtureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"pastFixtureCell" forIndexPath:indexPath];
// Configure the cell...
PastFixture *thisFixture = [pastFixturesArray objectAtIndex:indexPath.row];
//string to store the match result and score result
NSMutableString *matchString = [[NSMutableString alloc] init];
NSMutableString *matchScoreString = [[NSMutableString alloc] init];
//configure match string
[matchString appendFormat:@"%@ vs %@",thisFixture.homeTeam.teamName, thisFixture.awayTeam.teamName];
//configure the score string
[matchScoreString appendFormat:@"%ld - %ld", thisFixture.homeScore, thisFixture.awayScore];
//configure cell labels
cell.teamsVSTextLabel.text = matchString;
cell.teamsScoreDetailLabel.text = matchScoreString;
cell.teamsScoreDetailLabel.textColor = [UIColor blueColor];
return cell;
}
如果在视图首次加载并且不重新加载表数据时填充表,则自定义单元格将起作用,如果我不使用自定义单元格,则自定义单元格也将起作用,因此该问题特定于使用自定义单元格重新加载表。 有人可以帮忙吗?
编辑并且我收到EXC_BAD_ACCESS code = 2错误消息,所以它可能与内存有关
编辑2我的线程1:
编辑3:我认为这是问题所在。 使用自定义单元格,我得到空对象:/
这是我的自定义单元的实现文件:
#import "FixtureTableViewCell.h"
@implementation FixtureTableViewCell
@synthesize teamsVSTextLabel, teamsScoreDetailLabel;
- (void)awakeFromNib {
// Initialization code
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
teamsVSTextLabel.text = @".";
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
您是否在viewDidLoad
注册了tableCell? [self.tableView registerClass:[FixtureTableViewCell class] forCellReuseIdentifier:@"pastFixtureCell"];
编辑:
不要忘记检查单元格是否为零。
if (cell == nil) {
cell = [[FixtureTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle @"pastFixtureCell"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.