2017-04-10 19 views
0

here when i define a cell ,,then in picker it did not recognize and always be 0. so the label always be empty.OR rather then when i update my collection view then all element(9 element)of cell has been updated with selected value.now what i do for select a particular cell's label value and where i am wrong ?表示コレクションビューのセル

のparticularlabelにピッカービューから選択された値が、私は、タグとbutton.whenでラベルを含むcollectionviewセルを持つピッカービューが開いているボタンを、私をクリックしてください私は選択した行の値を選択しました。今、選択した値で特定のセルのラベルを更新したいのですが、すべてのセルのラベルが更新されました。

**- (UICollectionViewCell *)collectionView: 
(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath 

{ 
UICollectionViewCell *cell ; 
    static NSString *identifier = @"Cell"; 

{ 


    cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier   forIndexPath:0]; 

    NSURL *urlImage = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIImageURL, [[infoArray objectAtIndex:indexPath.row] valueForKey:@"product_image"]]]; 

    RemoteImageView *productImageView = (UIImageView *)[cell viewWithTag:100]; 
    productImageView .imageURL = urlImage; 

    UILabel *lblProductName = (UILabel *)[cell viewWithTag:101]; 
    [lblProductName setText:[[infoArray objectAtIndex:indexPath.row] valueForKey:@"product_name"]]; 


    NSArray *arrayProductQuantity =[[infoArray objectAtIndex:indexPath.row] valueForKey:@"product_qty"]; 
    for (NSDictionary *dicQuantity in arrayProductQuantity) 
    { 

     NSLog(@"quantity_name %@",[dicQuantity valueForKey:@"quantity_name"]); 
     if([arrayProductQuantity objectAtIndex:0]) 
     { 
      NSString*prodctPrice =[[infoArray objectAtIndex:indexPath.row] valueForKey:@"product_price"]; 
      float value = [prodctPrice intValue]; 
      NSString* qntyValue =[dicQuantity valueForKey:@"value"]; 
      float quntyValueInt=[qntyValue intValue]; 
     if([qntyValue isEqual:@"1000"]) 
      { 
      value=(value/1000*quntyValueInt); 
       float roundedValue = round(2.0f * value)/2.0f; 
       NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
       [formatter setMaximumFractionDigits:1]; 
       [formatter setRoundingMode: NSNumberFormatterRoundDown]; 

       NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:roundedValue]]; 

       UILabel *lblProductprice = (UILabel *)[cell viewWithTag:102]; 
       [lblProductprice setText:numberString]; 

       UILabel *lblProductQuantity = (UILabel *)[cell viewWithTag:103]; 
       lblProductQuantity.text = [dicQuantity valueForKey:@"quantity_name"] ; 

       UILabel *selectedCategory = (UILabel *)[cell viewWithTag:604]; 
       selectedCategory.text = lblRow.text; 

      } 
     else 
      { 
       value=ceil(value/1000*quntyValueInt); 
       float roundedValue = round(2.0f * value)/2.0f; 
       NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
       [formatter setMaximumFractionDigits:1]; 
       [formatter setRoundingMode: NSNumberFormatterRoundDown]; 

       NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:roundedValue]]; 

       UILabel *lblProductprice = (UILabel *)[cell viewWithTag:102]; 
       [lblProductprice setText:numberString]; 


       lblProductQuantity = (UILabel *)[cell viewWithTag:103]; 
       lblProductQuantity.text = [dicQuantity valueForKey:@"quantity_name"] ; 

      } 

      } 
} 
    } 

    return cell; 

}  

     -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
    { 

    detailViewController* myvc1 = [self.storyboard 
    instantiateViewControllerWithIdentifier:@"detailViewController"]; 

    myvc1.cat_dict=[infoArray objectAtIndex:indexPath.row]; 
     myvc1.fromVC = @"product"; 
     [self.navigationController pushViewController:myvc1 animated:true]; 
     } 
    #pragma mark picker for choose quntity 

    -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
    { 
     return 1; 
    } 

    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
    { 
     return [array_picker count]; 
    } 

** -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
    { 
     NSLog(@"You selected this: %@", [array_picker objectAtIndex: row]); 

     UILabel *selectedCategory = (UILabel *)[cell viewWithTag:604]; 
     selectedCategory.text = lblRow.text; 


    } ** 
+0

(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)componentは、あなたがこれまで –

+0

あなたが同じセル内のラベルやボタンの同じタグを与える必要があります行っているコードを更新してくださいこれらのコードを追加します。アクションメソッド内で、メソッドからセルを取得します。UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:index];ユーザーがピッカーから値を選択したときにセル内のラベルを更新する必要があります –

+0

@AravindBhuvanendranの動作メソッド内に既にcell.butがあります。セルを取得しませんでした - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)コンポーネント UILabel * selectedCategory =(UILabel *)[cell viewWithTag:604]; selectedCategory.text = lblRow.text;ここで私はcell.soを取得したい私は私の特定のセルのラベルを更新することができます。 – singh

答えて

0

これらのプロパティを追加しcellForRowatIndexPath方法で

@property (nonatomic, assign) NSInteger selectedIndex; @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

cell.button.tag = indexPath.row; [cell.button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];

新しいメソッドbuttonClickを追加します。これらのコードを追加します。

- (IBAction)buttonClick:(UIButton *)sender{ 
self.selectedIndex = sender.tag; 

// Show pickerview 

}

Insideは、

SampleCollectionViewCell *cell = (SampleCollectionViewCell *) [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0]]; // Assuming you have only single section 
cell.label.text = lblRow.text; 
関連する問題