2014-09-30 59 views
0
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *cellIdentifier = @"Cell"; 
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100]; 
[titleLabel setText:@"String"]; 
    return cell;} 

如何顯示陣列字符串中UILabelCollectionView線,顯示出Exception[titleLabel setText:@"String"];如何顯示陣列字符串中的UILabel在UICollectionView

+0

異常顯示[UICollectionViewCell的setText:]:無法識別的選擇發送到實例0xc531f30 2014-10-01 15:50:32.910 MyTabBar [3626:60B] ***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因:' - [UICollectionViewCell setText:]:無法識別的選擇器發送到實例0xc531f30' ***第一次拋出調用堆棧: – 2014-09-30 10:22:21

+0

'UILabel * titleLabel =(UILabel *)[cell viewWithTag:100];':'[cell viewWithTag: 100];'是'UICollectionViewCell'。即使你把它放入一個'UILabel',它也不會。 – Larme 2014-09-30 10:27:56

+0

你使用自定義的UICollectionView Cell嗎? – 2014-09-30 10:32:55

回答

0

晴與標籤的問題,原因按你的崩潰日誌

[UICollectionViewCell setText:]表示文字直接設置爲UICollectionViewCell而不是titleLabel。所以你必須檢查正確的標籤值..所以一些檢查標籤的標籤值。

否則檢查您是否已註冊您的收藏視圖單元格。

+0

標記值正確 – 2014-09-30 11:02:51

+0

我已經在我的應用程序中檢查了您的代碼..其工作完美,如果我設置相同的標記標籤。但如果我將相同的標籤設置爲其他組件,那麼應用程序崩潰。因此請檢查您是否已將相同的100標記設置爲集合視圖單元中的其他組件。 – Urmi 2014-10-01 05:04:20

+0

我的問題是remove.there是沒有問題的標記值,主要問題在於我在字符串上施加字符串,這就是問題。我會發布解決方案。 – 2014-10-01 05:13:37

0
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:  (NSIndexPath *)indexPath { 
static NSString *identifier = @"Cell"; 
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 
UILabel *label = (UILabel*)[cell.contentView viewWithTag:100]; 
cell.backgroundColor=[UIColor purpleColor]; 
label.textAlignment=NSTextAlignmentCenter;[ label setText:[printArray objectAtIndex:indexPath.row]]; 
return cell; }