![](/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.