简体   繁体   English

当我使用自定义uitableviewcell重新加载tableView时,ios应用程序崩溃

[英]ios app crashes when I reload tableView with custom uitableviewcell

I'm created a custom table view cell 我创建了一个自定义表格视图单元格

@interface FixtureTableViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *teamsVSTextLabel;
@property (weak, nonatomic) IBOutlet UILabel *teamsScoreDetailLabel;

@end

I make an asynchronous request to a server for data, and when it returns I reload the tables data. 我向服务器发出异步请求以获取数据,并在服务器返回时重新加载表数据。 This is my 这是我的

//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;
}

The custom cell works if I populate the table when the view first loads and I don't reload the table data, and it also works if I don't use custom cells, so the problem is specific to reloading my table with custom cells. 如果在视图首次加载并且不重新加载表数据时填充表,则自定义单元格将起作用,如果我不使用自定义单元格,则自定义单元格也将起作用,因此该问题特定于使用自定义单元格重新加载表。 Can someone help please? 有人可以帮忙吗?

EDIT And I'm getting an EXC_BAD_ACCESS code=2 error message, so it's probably something to do with memory 编辑并且我收到EXC_BAD_ACCESS code = 2错误消息,所以它可能与内存有关

轨迹图

EDIT 2 My thread 1: 编辑2我的线程1: 威胁1

EDIT 3: I think THIS is the problem. 编辑3:我认为这是问题所在。 With custom cells I get null objects :/ 使用自定义单元格,我得到空对象:/ 单元格为空

Here is my custom cell's implementation file: 这是我的自定义单元的实现文件:

#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

Did you register the tableCell in viewDidLoad ? 您是否在viewDidLoad注册了tableCell? [self.tableView registerClass:[FixtureTableViewCell class] forCellReuseIdentifier:@"pastFixtureCell"];

EDIT: 编辑:

Don't forget to check if the cell is nil. 不要忘记检查单元格是否为零。

if (cell == nil) {
    cell = [[FixtureTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle @"pastFixtureCell"];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ios:在自定义UITableViewCell中的CALayer上绘图会导致应用崩溃 - ios: Drawing on CALayer in custom UITableViewCell crashes app 当我尝试滚动TableView时应用崩溃 - app crashes when i try to scroll the tableview 重新加载tableview应用程序后,僵尸异常崩溃 - After reload of tableview app crashes with zombie exception 从后台打开应用程序时,iOS Swift 3重新加载TableView - iOS swift 3 reload tableview when open app from background 从tableview部分删除最后一行时,iOS应用程序崩溃 - iOS app crashes when deleting the last row from a tableview section 在iOS 7中在viewDidLayoutSubviews应用中设置新的Tableview框架时崩溃 - When set new frame of tableview in viewDidLayoutSubviews app crashes in iOS 7 点击UITableViewCell时应用崩溃 - App crashes when tapping a UITableViewCell 当我将UITableViewCell作为AnyObject传递时,我的应用程序崩溃了? 到另一个功能 - My App crashes when I pass a UITableViewCell as AnyObject? to an other function tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)将UITapGestureRecognizer添加到自定义UITableViewCell时不起作用 - tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) Doesn't work when I add a UITapGestureRecognizer to my custom UITableViewCell 自定义UITableViewCell在滚动TableView时发生更改 - Custom UITableViewCell changes when TableView scrolled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM