2016-07-20 3 views
0

私はこの質問をどこでも検索しましたが、これに対する正当な解決策は見つかりませんでした。 collectionviewの外にあるボタンをクリックすると、すべてのラベルの値にアクセスすることができます。collectionviewの外にはcollectionviewcellというラベルが付いています。いつものようにボタンのクリックでテーブルビューの外にラベル値にアクセスするnullを返す

for (int h=0; h<detailArr.count; h++) 
{ 
    NSNumber * num = [totalProductArr objectAtIndex:h]; 
    NSIndexPath * indexPath=[NSIndexPath indexPathForRow:[num intValue] inSection:0]; 
    NSLog(@"indexpath text is %@", indexPath); 
    AppointmentContentCell *cell = (AppointmentContentCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; 
    NSLog(@"text field text is %@", cell.serviceTypeLbl.text); 
} 


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    AppointmentContentCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 
    cell.serviceTypeLbl.text =[detailArr objectAtIndex:indexPath.row]; 
    cell.serviceCostLbl.text = [costArr objectAtIndex:indexPath.row]; 
    cell.totalServiceLbl.text = [totalServiceCount objectAtIndex:indexPath.row]; 

    return cell; 
} 
+0

細胞が再利用され、より便利である可能性があります。セルが画面上にない場合は、アクセスできません。セルにアクセスすることなく、基礎となるデータモデルからラベル値を得ることができるはずです – Paulw11

+0

こんにちはPaulw11あなたはこれを詳しく説明します。それは私のために非常に役立つでしょう。 – ashish

答えて

0

::私はiPhoneの画面上に表示が、スクロール上にあるかをラベルにnull値を取得しているセルのラベルの値をshowing.Hereが私のコードされて取得しています

取得ビュー(セル)からではなく、モデル(データソース配列)からの値。

これはあなたのコードと同じことが、私はロジックが、これはすべてのラベル(配列)の値をログに記録する例を示すために

for (NSInteger h = 0; h < detailArr.count; h++) 
{ 
    NSNumber *num = totalProductArr[h]; 
    NSLog(@"text field text is %@", detailArr[num.integerValue]); 
} 

を意図されていることはよく分かりません。あなたは無関係な配列のカップルではなく、カスタムクラスを使用する場合は

for (NSInteger h = 0; h < detailArr.count; h++) 
{ 
    NSLog(@"Service Type is %@", detailArr[h]); 
    NSLog(@"Service Cost is %@", costArr[h]); 
    NSLog(@"Total Service is %@", totalServiceCount[h]); 
} 

関連する問題