2011-07-06 23 views
5

Tek görünümde iki eylem sayfası oluşturdum. İki düğme vardır, her biri bir eylem sayfası başlatır.Tek görünümde iki eylem sayfası oluşturma

Sorun: her iki eylem sayfasında da ilk seçime bastığımda aynı eylem tetiklenir.

-(IBAction) ChangeArrow:(id)sender{ 
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Arrow" 
                 delegate:self 
               cancelButtonTitle:@"cancel" 
              destructiveButtonTitle:@"Red" 
               otherButtonTitles:@"Blue",@"Black",nil]; 
[actionSheet showInView:self.view]; 
[actionSheet release];} 
- (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ 
if (buttonIndex ==[actionSheet destructiveButtonIndex]) { 
    self.bar.image=[UIImage imageNamed:@"red"]; 

} 
else if(buttonIndex == 1){ 
    self.bar.image=[UIImage imageNamed:@"blue"]; 

} 
else if(buttonIndex == 2){ 
    self.bar.image=[UIImage imageNamed:@"dark"];} 
} 

// İkinci Eylem bilançosu:: Farklı bir değere her actionsheet üzerindeki etiket özelliğini ayarlayın

-(IBAction) Background:(id)sender{ 
UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Change Background" 
                 delegate:self 
               cancelButtonTitle:@"cancel" 
              destructiveButtonTitle:@"Sky" 
               otherButtonTitles:@"Thumbs",@"Smiley",nil]; 
[actionSheet2 showInView:self.view]; 
[actionSheet2 release]; 
} 
- (void) actionSheet2: (UIActionSheet *)actionSheet2 didDismissWithButtonIndex:(NSInteger)buttonIndex { 
if (buttonIndex ==[actionSheet2 destructiveButtonIndex]) { 
    self.background.image=[UIImage imageNamed:@"sky"]; 

} 
else if(buttonIndex == 1){ 
    self.background.image=[UIImage imageNamed:@"thumbs"]; 

} 
else if(buttonIndex == 2){ 
    self.background.image=[UIImage imageNamed:@"smiley"];} 
} 
+0

bir kod yazarken thnx, hala bazı sorunlar yaşıyorum Dickison daniel: P –

cevap

25

İşte benim kod. Ardından, yönteminizi hangi işlem sayfasından aradığınızı görmek için sender.tag dosyasını kontrol edebilirsiniz.

Ex.

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Arrow" 
                delegate:self 
              cancelButtonTitle:@"cancel" 
             destructiveButtonTitle:@"Red" 
              otherButtonTitles:@"Blue",@"Black",nil]; 
actionSheet.tag = 1; 
UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Change Arrow" 
                 delegate:self 
               cancelButtonTitle:@"cancel" 
              destructiveButtonTitle:@"Red" 
               otherButtonTitles:@"Blue",@"Black",nil]; 
actionSheet2.tag = 2; 

Sonra

- (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ 
if(actionSheet.tag == 1) { 
    //do something 
} else if(actionSheet.tag == 2) { 
    //do something else 
} 
} 
+0

David'in doğru cevaba eklemek, bunu temsilci olan gönderici görmek için kontrol edin yöntem. –

+0

ve bu nasıl yapılabilir? –

+0

David'den David'e: bkz. Davids'deki düzenlenmiş örnek, en iyi/en kolay şekilde yanıtlıyor –

İlgili konular