我正在使用帶有標準單元格的表格視圖的iPad應用程序,選擇自定義單元格時,它應該展開並加載自定義的nib文件。這對第一次選擇很好。iOS - 在第二次加載時加載自定義表格單元格錯誤
如果我選擇一個標準的單元格,它會加載筆尖,如果再次選擇它會恢復正常,第二次加載時會拋出EXC_BAD_ACCESS
錯誤(我不認爲我會得到xcode錯誤,似乎是最抽象的)。
我的代碼如下而行是當它從隊列中重複使用的單元格,第三行:
if([listCells objectAtIndex:indexPath.row] == @"open") {
NSLog(@"Loading open cell at %i", indexPath.row);
CustomMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomMessageCell"];
//Loads the nib file and grabs the last object, presumably the table cell, as it is the only object in the file.
if(cell==nil) {
cell = [[[[NSBundle mainBundle] loadNibNamed:@"CustomMessageCell" owner:self options:nil] lastObject] autorelease];
}
UILabel *message = (UILabel *) [cell viewWithTag:1];
UIButton *approve = (UIButton *)[cell viewWithTag:4];
message.text = @"Test";
return cell;
任何幫助非常感謝,謝謝!
謝謝,但即使刪除,導致問題。我添加了它,假設它是一個內存問題。猜測它不是? –
你不調用alloc或保留,所以你不應該autorelease。 – SK9