2016-03-28 13 views
1

TableView ve UILabel'dan oluşan bir UITableViewController var. UITableViewSource, verileri UITableViewCell aracılığıyla TableView'a besler. UITableViewCell, öğeleri ekleyebilen bir Step'den oluşur ve Label bu değeri tutar.iOS'ta Özel Hücredeki UILabel değerlerini aşan UIStepper

Ben kullanıcı Step hafifçe dokunduğunda ve ben bu işe almak gibi olamaz zaman UILabelUIViewController güncellemek istiyorum ...

Herhangi bir yardım/ipuçları

büyük takdir! İşte benim test projemden örnek kod, kullanılmayan bir sürü kod var ama bu sadece bir test. Kod My Custom Hücre Sınıfı "StepperDetailsCell" dir

olduğunu

sayesinde.

@interface StepperDetailsCell : UITableViewCell 
@property (nonatomic,weak) id <StepperDetailsCellDelegate> delegate; 
@property (strong, nonatomic) IBOutlet UIImageView *imagegroceries; 
@property (strong, nonatomic) IBOutlet UIStepper *objstepper; 
@property (strong,nonatomic) IBOutlet UILabel *lblsteppervalue; 


    -(IBAction)stepperclicked:(UIStepper*)sender; 

@end 

ve My tablo görünümü sınıfı "SecondViewController"

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *simpleTableIdentifier = @"Cell"; 

    cell = (StepperDetailsCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil){ 

     cell = (StepperDetailsCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 

    } 

    [cell.imagegroceries setImage:[UIImage imageNamed:[[self.didSelectedImages sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]objectAtIndex:indexPath.row]]]; 

    [cell.objstepper addTarget:self action:@selector(stepperValuechanges:) forControlEvents:UIControlEventValueChanged]; 

    cell.lblsteppervalue.text = [self.quantityArr objectAtIndex:indexPath.row]; 


    return cell; 
} 

Pragma işareti olarak adlandırılır - Adım Eylem Metodu Burada

-(void)stepperValuechanges:(UIStepper *)sender{ 

    CGPoint stepperPosition = [sender convertPoint:CGPointZero toView:self.tableView]; 
    indexPath1 = [self.tableView indexPathForRowAtPoint:stepperPosition]; 

    if (indexPath1 != nil) 
    { 
     float val = sender.value; 
     valueInt = (int)val; 

     [self.quantityArr replaceObjectAtIndex:indexPath1.row withObject:[NSString stringWithFormat:@"%i",valueInt]]; 
     NSLog(@"%@",self.quantityMDict); 
    } 

    [self.tableView reloadData]; 

} 

, her şey düzgün çalışıyor, ancak her yeni hücredir tableview alttan yükleme, o zaman yeni hücre adımı kaybolan hücre stepper olarak hareket eder.

+0

sorunuzu hiçbir kod yoktur. –

+0

@Nitin Gohel, Şimdi kodumu ekledim –

cevap

0

Son olarak 3 gün sonra problemimi çözdüm.

Sadece .. aşağıdaki yolu gibi karşılık gelen Kontrolör Object UIStepper Nesne eylemi pişirilmeden önce UIStepper değerini ayarlamak

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {

static NSString *simpleTableIdentifier = @"Cell"; 

cell = (StepperDetailsCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil){ 

    cell = (StepperDetailsCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 

} 

[cell.imagegroceries setImage:[UIImage imageNamed:[[self.didSelectedImages sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]objectAtIndex:indexPath.row]]]; 

// sadece önceki değerini (bu değer, ben step nesneden kontrolör nesneye eylemi ateşlemeden önce, step karşılık gelen "quantityArr" adlı diziden) alınan ediyorum. İşte bu ..

[cell.objstepper setValue:[[self.quantityArr objectAtIndex:indexPath.row] doubleValue]]; 

[cell.objstepper addTarget:self action:@selector(stepperValuechanges:) forControlEvents:UIControlEventValueChanged]; 

cell.lblsteppervalue.text = [self.quantityArr objectAtIndex:indexPath.row]; 


return cell; 

}