{"id":1591,"date":"2012-09-25T19:13:22","date_gmt":"2012-09-25T15:13:22","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=1591"},"modified":"2012-09-25T19:18:39","modified_gmt":"2012-09-25T15:18:39","slug":"uialertview-with-uitextfield","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=1591","title":{"rendered":"UIAlertView with UITextField"},"content":{"rendered":"<p>I wanted to show an alertView to a user with a textField. This is what was achieved:<br \/>\n<a href=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2012\/09\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2012-09-25-\u0432-19.15.22.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2012\/09\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2012-09-25-\u0432-19.15.22-159x300.png\" alt=\"\" title=\"\u0421\u043d\u0438\u043c\u043e\u043a \u044d\u043a\u0440\u0430\u043d\u0430 2012-09-25 \u0432 19.15.22\" width=\"159\" height=\"300\" class=\"aligncenter size-medium wp-image-1593\" srcset=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2012\/09\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2012-09-25-\u0432-19.15.22-159x300.png 159w, https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2012\/09\/\u0421\u043d\u0438\u043c\u043e\u043a-\u044d\u043a\u0440\u0430\u043d\u0430-2012-09-25-\u0432-19.15.22.png 396w\" sizes=\"auto, (max-width: 159px) 100vw, 159px\" \/><\/a><br \/>\nFirst, I tried to use Block Alerts and ActionSheets, but I failed. Then I discovered, that there is a standart way to do this. There are some UIAlertView styles available beyond a default style: UIAlertViewStyleLoginAndPasswordInput, UIAlertViewStylePlainTextInput and UIAlertViewStyleSecureTextInput. In this case we will use the second one. Works on iOS 5 and later:<\/p>\n<pre class=\"alwawee-code\"><code>&lt;br \/&gt;\nUIAlertView *av = [[UIAlertView alloc] initWithTitle:LS(@\u201dDocument file name\u201d) message:@\u201dPlease enter document file name.\u201d delegate:self cancelButtonTitle:LS(@\u201dCancel\u201d) otherButtonTitles:LS(@\u201dSave\u201d), nil];&lt;br \/&gt;\nav.alertViewStyle = UIAlertViewStylePlainTextInput;&lt;br \/&gt;\n[av textFieldAtIndex:0].delegate = self;&lt;br \/&gt;\n[av textFieldAtIndex:0].text = self.mcAttachDisplayed.fileName;&lt;br \/&gt;\n[av show];&lt;br \/&gt;\n<\/code><\/pre>\n<p>Then, you should define two protocols UITextFieldDelegate, UIAlertViewDelegate.<br \/>\nAnd implement methods: <\/p>\n<pre class=\"alwawee-code\"><code>&lt;br \/&gt;\n\u2013 (BOOL)textFieldShouldReturn:(UITextField *)textField&lt;br \/&gt;\n{&lt;br \/&gt;\n    [textField resignFirstResponder];&lt;br \/&gt;\n    return YES;&lt;br \/&gt;\n}&lt;\/p&gt;\n&lt;p&gt;\u2013 (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex&lt;br \/&gt;\n{&lt;br \/&gt;\n    NSLog(@\u201dButton index clicked:%d\u201d, buttonIndex);&lt;\/p&gt;\n&lt;p&gt;    switch (buttonIndex) {&lt;br \/&gt;\n        case 0:&lt;br \/&gt;\n            break;&lt;br \/&gt;\n        case 1:{&lt;br \/&gt;\n            NSLog(@\u201dSave Clicked\u201d);&lt;br \/&gt;\n            UITextField *textField = [alertView textFieldAtIndex:0];&lt;br \/&gt;\n            NSString *text = textField.text;&lt;\/p&gt;\n&lt;p&gt;            break;&lt;br \/&gt;\n        }&lt;br \/&gt;\n        default:&lt;br \/&gt;\n            break;&lt;br \/&gt;\n    }&lt;br \/&gt;\n}&lt;br \/&gt;\n<\/code><\/pre>\n<p>References:<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/9962538\/adding-textfield-to-uialertview\" title=\"http:\/\/stackoverflow.com\/questions\/9962538\/adding-textfield-to-uialertview\" target=\"_blank\">StackOverFlow question<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to show an alertView to a user with a textField. This is what was achieved: First, I tried to use Block Alerts and ActionSheets, but I failed. Then I discovered, that there is a standart way to do this. There are some UIAlertView styles available beyond a default style: UIAlertViewStyleLoginAndPasswordInput, UIAlertViewStylePlainTextInput and UIAlertViewStyleSecureTextInput. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1591","post","type-post","status-publish","format-standard","hentry","category-ios"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>UIAlertView with UITextField - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=1591\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UIAlertView with UITextField - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"I wanted to show an alertView to a user with a textField. This is what was achieved: First, I tried to use Block Alerts and ActionSheets, but I failed. Then I discovered, that there is a standart way to do this. There are some UIAlertView styles available beyond a default style: UIAlertViewStyleLoginAndPasswordInput, UIAlertViewStylePlainTextInput and UIAlertViewStyleSecureTextInput. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=1591\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-25T15:13:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-09-25T15:18:39+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"UIAlertView with UITextField\",\"datePublished\":\"2012-09-25T15:13:22+00:00\",\"dateModified\":\"2012-09-25T15:18:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591\"},\"wordCount\":175,\"commentCount\":0,\"articleSection\":[\"iOS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591\",\"name\":\"UIAlertView with UITextField - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2012-09-25T15:13:22+00:00\",\"dateModified\":\"2012-09-25T15:18:39+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=1591#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UIAlertView with UITextField\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UIAlertView with UITextField - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=1591","og_locale":"en_US","og_type":"article","og_title":"UIAlertView with UITextField - Denis Kutlubaev","og_description":"I wanted to show an alertView to a user with a textField. This is what was achieved: First, I tried to use Block Alerts and ActionSheets, but I failed. Then I discovered, that there is a standart way to do this. There are some UIAlertView styles available beyond a default style: UIAlertViewStyleLoginAndPasswordInput, UIAlertViewStylePlainTextInput and UIAlertViewStyleSecureTextInput. [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=1591","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2012-09-25T15:13:22+00:00","article_modified_time":"2012-09-25T15:18:39+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=1591#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=1591"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"UIAlertView with UITextField","datePublished":"2012-09-25T15:13:22+00:00","dateModified":"2012-09-25T15:18:39+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=1591"},"wordCount":175,"commentCount":0,"articleSection":["iOS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=1591#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=1591","url":"https:\/\/blog.alwawee.ru\/?p=1591","name":"UIAlertView with UITextField - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2012-09-25T15:13:22+00:00","dateModified":"2012-09-25T15:18:39+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=1591#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=1591"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=1591#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"UIAlertView with UITextField"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/1591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1591"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/1591\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}