UIActionSheet
,它有按鈕標題,我從數組中取出標題。我想獲得按鈕標題並顯示在UILabel
,我做了,但如果我按取消按鈕取消按鈕還顯示,我不想在UILabel
下面的代碼,我試圖顯示取消按鈕標題,UIActionSheet取消按鈕無法正常工作
- (IBAction)site_Selection:(id)sender {
NSArray *array = @[@"one",@"two",@"three",@"Smart Gladiator1"];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
actionSheet.delegate = self;
for (NSString *title in array) {
[actionSheet addButtonWithTitle:title];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet showInView:self.view];
}
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
self.btn_site_selection.titleLabel.text = [actionSheet buttonTitleAtIndex:buttonIndex];
}
請幫我做這件事,
感謝@rckoenes,這是工作的罰款:你可以用
cancelButtonIndex
上UIActionSheet
做到這一點 – user6183984