iPhoneアプリを開発中です。コレクションビュー上に配置したラベルに、
plistで準備したテキストを表示する方法についてアドバイスをいただけないでしょうか。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ CollectionCell *cell = (CollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; [cell setImage:[_objects objectAtIndex:indexPath.item]]; if(indexPath.section==0){//セクション0のセル cell.backgroundColor = [UIColor greenColor]; // plistのパスはここで取得する NSString* pth = [[NSBundle mainBundle]pathForResource:@"Label" ofType:@"plist"]; // 読み込んだplistを元に、DictionaryList(NSDictionary型)を作る DictionaryList = [NSDictionary dictionaryWithContentsOfFile:pth]; // plist内に準備したラベルのテキストを取得するためのキーをaaaとして準備する NSString *aaa=[[NSString alloc] initWithFormat:@"ラベル%ld",(long)indexPath.row]; // キーaaaを使ってDictionaryListからテキストを引き出してstrとする NSString *str = [DictionaryList objectForKey:aaa]; // ラベルのオブジェクトはここで作る UILabel *label = (UILabel *)[cell viewWithTag:1]; // 引き出したテキスト「str」をlabelにテキストとして放り込む label.text = str; } return cell; }
上記のコードでの問題点は、テキスト「str」を取得するまではできたのですが、
なぜかそれを「label.text」に放り込むことができず、NULLを吐いてしまうところです。
どなたか解決策をご教示いただけないでしょうか。
以上、何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。