Table view in action sheet in xamarin ios - uitableview

How we can add a table view in the action sheet. am using xamarin ios. I need an action sheet with a table view which has an accordion. I can do normal table view with accordion. I need the table view inside the action sheet

The first thing you should do is to use UIAlertController instead of the UIActionSheet, which was deprecated in iOS 8. You'll have a more future proof app with an easier to work with alert functionality.
UIAlertController inherits from UIViewController which let's you add subviews as you desire.
// Create a new UIAlertController
var alertController = UIAlertController.Create("Alert Title", "Some text here", UIAlertControllerStyle.ActionSheet);
// Add your custom view to the alert. Any UIView can be added.
var yourTableView = new UITableView();
alertController.View.AddSubview(yourTableView)
// Add Actions
alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, alert => Console.WriteLine ("Ok clicked")));
alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, alert => Console.WriteLine ("Cancel clicked")));
// Show the alert
controller.PresentViewController(alertController, true, null);
Here's an example of this in action, although it's in Swift.

Related

How to disable touch outside screen dismiss view using MDCAlertController Material Design - swift

I am new iOS programming and now am fascinated in using MaterialComponents which provide by google. Now i facing one problem in component named Dialog.
When the view has been pop up on screen when i touch outside that pop up view and then that view has been dismiss. I don't want that to happen in my app.
I don't want user to click outside popup view to dismiss that popup view. What i want i just want user to click on action button that i provide for user's choice then the view should be dismiss when click on that action button only.
Really glade that you help.
MDCAlertController is inherited from UIViewController.
So, in order to restrict user to click outside MDCAlertController you have to access its property named view and then superview?.subviews[0].isUserInteractionEnabled = false
I have completed one example using MDCAlertController
let alert = MDCAlertController(title: title, message: message)
alert.buttonTitleColor = UIColor(red:0.03, green:0.62, blue:0.09, alpha:1.0)
//MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
let okayAction = MDCAlertAction(title: "Okay") { (action) in
print("User click okay")
}
let cancelAction = MDCAlertAction(title: "Cancel", handler: nil)
alert.addAction(okayAction)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: {
// When the Dialog view has pop up on screen then just put this line of code when Dialog view has completed pop up.
alert.view.superview?.subviews[0].isUserInteractionEnabled = false
})
use this.
let alert = MDCAlertController(title: title, message: message)
alert.mdc_dialogPresentationController.dismissOnBackgroundTap = false
https://material.io/develop/ios/components/dialogs/api-docs/Categories/UIViewController_28MaterialDialogs_29.html
https://material.io/develop/ios/components/dialogs/api-docs/Classes/MDCDialogPresentationController.html#/c:objc(cs)MDCDialogPresentationController(py)dismissOnBackgroundTap

Preloaded text in an alert

I was wondering if it was possible to have an alert with preloaded text in it. For example, if my app guessed something I would want the guess to appear in the alert text box but the user could delete the text and change the answer if they wanted to.
Thank you
Have you had a look at this page : How to add a TextField to UIAlertView in Swift ?
You could put textfields (or anything else you'd like) inside the alertview and so that the user could interact with it more deeply :)
Vincent
yes you can. You can create a custom alertView from a xib and you can input there an UITextField ,so the user can have the opportunity to change the text
Simply Create an alert controller leave the title and message empty and add a TextField to your alert that way you can preload your text to the TextField and user can also edit the text
Just add text field in alert controller.
let alertController = UIAlertController(title: "title", message: "please enter words", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addTextFieldWithConfigurationHandler { (txtUsername) -> Void in
usernameTextField?.text = "preload"
usernameTextField?.placeholder = "placeholder"
}
self.presentViewController(alertController, animated: true, completion: nil)

Add an animation image per image inside a UIAlertController SWIFT

I have a function to display an UIAlertController. Below the title and the text, I would like to display an animation image per image. I have 13 images to loop.
func alertDownloadInProgress(text:String, sender:UIViewController) -> UIAlertController {
var alert = UIAlertController(title: "Alert", message: text, preferredStyle: UIAlertControllerStyle.Alert)
sender.presentViewController(alert, animated: true, completion: nil)
return alert
}
Is it possible to use an UIAlertController or I have to custom completely my pop up?
I don't know of a way to customize a UIAlertController like that; they only have three properties--title, message, preferredStyle, and textFields--none of which you can add a UIImageView to.
I would recommend creating a custom modal presentation controller. I actually just wrote an answer on how to do that. Of course you'll center your custom view instead of pinning it to the right, but that answer could at least help you get started with the wacky world of UIPresentationControllers.

How to get the title of the selected UIAlertController of type action sheet for iOS 8.0+ into a label?

I have created a drop down with text and button, when the drop down button is clicked the data is populated in the UIAlertController of type action sheet.
Now to replicate drop down behavior need to set the text of textfield as the clicked UIAlertActon title.
But I am not able to find any way to fetch the title and set it as text of UITextField. I am using swift.
Please suggest.
When you create your UIAlertAction, you can add a handler which gets called when the button is tapped. Your action gets passed into the handler, so you can access its title property there:
let myAction = UIAlertAction(title: "Option 1", style: .Default) { action in
println(action.title)
}
You can see this in the docs for UIAlertAction.

how to make a slider appear when a button is pressed in Swift?

i'm making a draw application, and i want a slider to appear when the user taps on a button, for example to set the width of a line .
Can I just add an alert and put a slider in it ?
Using Swift 3.0, you can add a slider (or other object) to a UIAlertController subview. The following example is triggered by an #IBAction button to use and update the UserDefaults: Example of a UISider inside a UIAlertController
#IBAction func sliderButton(_ sender: AnyObject) {
//get the Slider values from UserDefaults
let defaultSliderValue = UserDefaults.standard.float(forKey: "sliderValue")
//create the Alert message with extra return spaces
let sliderAlert = UIAlertController(title: "Update Defaults", message: "Increase/Decrease the slider…\n\n\n\n\n\n", preferredStyle: .alert)
//create a Slider and fit within the extra message spaces
//add the Slider to a Subview of the sliderAlert
let slider = UISlider(frame:CGRect(x: 10, y: 100, width: 250, height: 80))
slider.minimumValue = 1
slider.maximumValue = 100
slider.value = defaultSliderValue
slider.isContinuous = true
slider.tintColor = UIColor.red
sliderAlert.view.addSubview(slider)
//OK button action
let sliderAction = UIAlertAction(title: "OK", style: .default, handler: { (result : UIAlertAction) -> Void in
UserDefaults.standard.set(slider.value, forKey: "sliderValue")
})
//Cancel button action
let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
//Add buttons to sliderAlert
sliderAlert.addAction(sliderAction)
sliderAlert.addAction(cancelAction)
//present the sliderAlert message
self.present(sliderAlert, animated: true, completion: nil)
}
The subview can be positioned just about anywhere. To make room for the slider, I added a few extra line breaks in the message to open up some space. The slider will appear and disappear with the Alert message.
Welcome to Stack Overflow.
Your question is more of a basic programming question than a Swift question.
I don't think you can put a slider in an alert. Apple introduced the UIAlertController class recently, and their docs say you should us that rather than UIAlertView for new development.
A UIAlertController lets you create alerts and action sheets, and add actions. The actions are shown as buttons. There is also a facility for adding text fields. I don't think there is any facility for adding other view objects like sliders however.
The now-deprecated UIAlertView is also not set up for adding custom fields like sliders.
You could put the slider on your view somewhere and set it's hidden property to true, then in the buttons action method, set mySlider.hidden = false.
However it sounds like you want your slider to appear on top of your UI, then go away when the user is done with it.
You could create a view with a slider and a dismiss button on it, put it on top of your view controller's content view, and set it's hidden flag to true. When the user taps your button, set hidden = false and the view will appear on top, rather like an alert does. You'd set up constraints so the slider-containing view would be centered on the screen and sized appropriately.
toggle the hidden property.
slider.hidden = true//hide it
slider.hidden = false//show it

Resources