我在我的代碼中將其更改爲descriptionLabel,它不是我認爲的保留關鍵字,但仍稱其爲descriptionLabel好得多。修復原因sigabort
編譯器不會糊塗,這確實是一個合理的解釋。
代碼現在:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
RhythmCell *cell = (RhythmCell *)[cv dequeueReusableCellWithReuseIdentifier:@"RhythmCell" forIndexPath:indexPath];
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(5, 20, cell.bounds.size.width-10, cell.bounds.size.height+150)];
title.font = [UIFont systemFontOfSize:15];
title.tag = indexPath.row;
title.numberOfLines = 2;
title.textAlignment = NSTextAlignmentCenter;
title.text = cell.descriptionLabel.text;
[cell.contentView addSubview:title];
return cell;
}
什麼是「標題」?向我們展示代碼! – Shai
我想你應該先嚐試一些其他的字符串;即'title.text = @「test」;'並且看看它是否會起作用。 – Unheilig
這似乎是一個很好的解決方案,同時刪除該警告並且還防止異常: '的NSString * descriptiontext描述= [(的UILabel *)cell.descriptionLabel mutableCopy];' @Unheilig,問題不在於它不會顯示標籤中的文字,問題是(是)它引起警告,警告是不好的,所以在代碼功能之後,我試圖讓它們解決。解決這個問題似乎沒有效果,而是導致了一個異常。這個解決方案效果很好。 - JopieK 5分鐘前 – JopieK