3

そのため、複数のコレクション ビュー (正確には 4 つ) を持つアプリの Xcode4 で作業してきました。

画面いっぱいに表示される 1 つの大きなコレクション ビューを含む下部の「メイン」ビューと、側面から引き出すことができ、1 つに積み重ねられた 3 つの狭い水平スクロール コレクション ビューを含む小さな「引き出し」ビューの 2 つのビューがあります。他のトップ。

メソッドでタグとifステートメントを使用してセルを作成しましたcellforitematpath。xcode 4、および私がxcode 4で作成し、現在xcode 5で開いているプロジェクトで、これは機能します。下部に という警告 (エラーではない) が表示されますがcontrol may reach end of non void function、それでもビルドして実行でき、動作します。

xcode 5 の新しいプロジェクトでは、同じコードで「コントロールが非 void 関数の終わりに到達する可能性があります」というエラーが表示され、ビルドと実行が許可されません。これはとてつもなくイライラします。セルにデータを入力する配列がない限り、セルを返したくありません。「return nil」が何を意味するのかさえわかりません。これをオフにする方法について何か提案はありますか?

以下は間違いなくきれいではありません。自己責任で入力してください。

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView
                   cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView.tag == 0){
        static NSString *CellIdentifier = @"subjectCell";
        SubjectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

        AHSubject *cellSubject = [self.subjectsArray objectAtIndex:indexPath.row];

        [[cell subjectLabel]setText:cellSubject.name];

        return cell;
    }
    else if (collectionView.tag == 1){
        if ([categoryArray count] > 0) {
            static NSString *CellIdentifier = @"categoryCell";
            CategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

            AHCategory *cellCategory = [categoryArray objectAtIndex:indexPath.row];

            [[cell categoryLabel]setText:cellCategory.name];

            return cell;
        }
    }
    else if (collectionView.tag == 2){
        if ([subcategoryArray count] > 0) {
            static NSString *CellIdentifier = @"subcategoryCell";
            GroupCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

            AHCardGroup *cellSubcategory = [subcategoryArray objectAtIndex:indexPath.row];

            [[cell subcategoryLabel]setText:cellSubcategory.name];

            return cell;
        }
    }
    else {
        if ([cardArray count] > 0) {
            static NSString *CellIdentifier = @"cardCell";
            CardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

            AHCard *cellCard = [cardArray objectAtIndex:indexPath.row];

            [[cell frontLabel]setText:cellCard.front];

            return cell;
        }
    }
    // return nil;
}
4

3 に答える 3

0

したがって、デフォルトが必要です。このメソッドは、表現されたオブジェクトの状態に基づいてスタイルを設定することを目的としています。

1 つのタグをオフにするか、デフォルトのビューを選択して、値に一致するタグがないものを返します。

于 2013-09-20T04:41:24.120 に答える