HeyI想要做到這一點我的按鈕和按鈕中有文本框我想這樣做,當我按下按鈕動作選取器成爲出現,並給出4至5列表的字符串無論我選擇它會在按鈕上的文本框中顯示。請通過添加一個目標你的按鈕幫我按鈕上的操作表選擇器IOS
-1
A
回答
1
開始。在Objective-C中,這將是這樣的:
[myButton addTarget:self
action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
然後創建方法buttonPressed
。這方面的一個例子是:
- (void)buttonPressed:(id)sender {
if ([sender isEqual:self.myButton]) {
//This is where you can create the UIAlertController
}
}
然後,創建UIAlertController
:
UIAlertController *myAlertController = [UIAlertController alertControllerWithTitle:@"Title"
message:@"Message"
preferredStyle:UIAlertControllerStyleActionSheet];
然後你創建你想有每個按鈕出現在動作片的動作。你需要有一個按鈕的標題和一個動作,儘管動作塊可以是空的。
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"Action 1"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//Whatever you want to have happen when the button is pressed
}];
[myAlertController addAction:action1];
//repeat for all subsequent actions...
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
// It's good practice to give the user an option to do nothing, but not necessary
}];
[myAlertController addAction:cancelAction];
最後,你目前的UIAlertController
:
[self presentViewController:myAlertController
animated:YES
completion:^{
}];
注:
如果您正在爲iPad和使用動作片風格的UIAlertController,那麼你將需要設置UIAlertController的來源。這是可以做到這樣的:
if ([sender isKindOfClass:[UIView class]]) {
if ([myAlertController.popoverPresentationController respondsToSelector:@selector(setSourceView:)]) { // Check for availability of this method
myAlertController.popoverPresentationController.sourceView = self.myButton;
} else {
myAlertController.popoverPresentationController.sourceRect = self.myButton.frame;
}
}
+0
另外值得注意的「按鈕標題」 –
+0
這是一個很好的觀點。我會將該註釋添加到我的答案中。 – Fennelouski
相關問題
- 1. iOS alertview操作按鈕
- 2. 作爲按鈕選擇器的參數 - iOS(Swift)
- 3. iOS - 在具有參數的按鈕上調用選擇器
- 4. 選擇表上的排序按鈕
- 5. 按鈕的選擇器
- 6. IOS中的按鈕操作問題
- 7. 製作一個JavaScript按鈕選擇器
- 8. 按鈕操作無法在視圖上的按鈕上工作
- 9. 按鈕的全包式選擇器(作爲替代:按鈕)
- 10. CakePHP表單操作按鈕
- 11. 選擇按鈕表 - 使用jQuery選擇
- 12. 單選按鈕上的單選按鈕選擇
- 13. Qlikview按鈕作出選擇
- 14. IOS - 如何從操作按鈕
- 15. 按鈕背景選擇器
- 16. 顏色選擇器按鈕
- 17. 安卓按鈕選擇器
- 18. iOS 11上的UIToolbar按鈕無法調用的操作UISearchController
- 19. 如何將按鈕添加到iOS文本選擇操作控件
- 20. 的按鈕操作
- 21. iOS按鈕處理程序,基於按鈕選擇的segue
- 22. UIToolBar上的完成按鈕無法操作 - iOS
- 23. 按鈕上的應用程序崩潰單擊操作iOS
- 24. 單選按鈕的Android操作
- 25. 如何阻止iOS PinchGesture選擇按鈕?
- 26. 製作單選按鈕,指向不同的網站上選擇此按鈕
- 27. 選擇列表操作
- 28. iOS - 用於UIButton操作的選擇器中的硬代碼值
- 29. iOS - 選擇標籤上的後退按鈕
- 30. 在Android中的文本選擇上沒有顯示操作欄按鈕?
當點擊動作片按鈕設置的TextField.text = @,你打 – sohil
,如果這是要在iPad上運行,一必須聲明'popoverPresentation'。通常是一個欄按鈕項目,或者定義一個'sourceRect'和一個'sourceView'。它會在iPad上崩潰,否則 –