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 ?從選擇器視圖的選擇的值顯示給集合視圖的小區
我有包含具有標籤和button.when標籤的的CollectionView細胞的particularlabel我點擊該按鈕選擇器視圖開我選擇了一個值選擇行。現在我想更新我的特定單元格的標籤與選定的值,但所有單元格的標籤已更新。當我從選擇器中選擇一個值時,我如何更新我的單個標籤。
**- (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;
} **
請你做了迄今 –
你應該給在同一小區的標籤和按鈕相同的標籤代碼更新。在action方法內部,您將從方法UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:index];中獲取單元格。你應該更新單元格內的標籤,當用戶從選擇器中選擇一個值 –
@AravindBhuvanendran在操作方法中,我已經得到了單元格。但是我沒有得到單元格 - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component UILabel * selectedCategory =(UILabel *)[cell viewWithTag:604]; selectedCategory.text = lblRow.text;在這裏我想要cell.so我可以更新我的特定單元格的標籤。 – singh