将选择的值从选择器视图显示到集合视图的单元格的特定标签

时间:2017-04-10 07:25:37

标签: ios objective-c uipickerview uicollectionviewcell

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 ?

  

我有一个collectionview单元格,其中包含带标签和按钮的标签。当我点击按钮时,选择器视图打开,我选择了一个值选择行。现在我想更新我的特定单元格&#39 ;带有选定值的标签,但所有单元格的标签都已更新。当我从选择器中选择一个值时,我会更新单个标签。

**- (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;


    } **

1 个答案:

答案 0 :(得分:0)

添加这些属性

$targeted_banners = BannerView::Where('camp_id', $id) ->where(function($query){$query->where('seat_target_status', true)->orWhere('seat_target_status', false);}) ->where('camp_target_status', false) ->where("created_at", ">=" $from_date) ->where("updated_at", "<=", $to_date) ->count();

在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];

}

在里面添加这些代码 - (IBAction)buttonClick:(UIButton *)sender{ self.selectedIndex = sender.tag; // Show pickerview

(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component