How to send email message from IOS application using 2 Views? - ios

I am an IOS noob and this may be a dumb question, so here it is. I have two views. View A and View B. View A has my textField (for my message) and View B has my send button. Is it possible to send text inputed in View A from my send button in View B? Or is there a better way to do this?
Basically what I am trying to do is share a message using a menu. After the user clicks the send message a popup will display asking the user how to send. (IE: Send as Email, Share on Twitter, Share on Facebook, or Cancel).
My FIRST VIEW
My SECOND VIEW
Also just so I am clear. I don't expect anyone to solve it just wondering if anyone has ever done something like this before. If you want to provide possible solution that would be awesome. But really, more or less, I am looking for some insight.

Question: "Is it possible to send text inputed in View A from my send button in View B? Or is there a better way to do this?"
Answer: Yes, it is possible. Here is a tutorial which contains an explanation of how to send an email from an app: http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/. In the toolbar in the first view you might consider using a standard system image, UIBarButtonSystemItemAction, instead of "Send Message." You might also consider using a UIActionSheet instead of the second view. Apple says, "Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task."

Yes this is possible through several methods. The most OO and IMO the best way will be to create a custom init method on ViewB.
Something like -(id) initWithEmail(NSString* email, NSString* message)

It is easy if all your widgets (the textfield, the button and the action sheet) are all ivars of the same view controller.
So, in the same controller, the button will trigger the selectSendingMethod which will display the pop up and each button of this sheet will call an adequate method.
That should solve your problem.

Related

Passing data between more than 2 viewcontrollers in Swift

My app contains TabBar controller with 5 viewcontrollers. It is possible to click on a button in each of viewcontrollers which will popup another view in which user can choose a setting. The button (which was clicked) is supposed to change its background according to chosen setting in each viewcontroller. So if the user clicks on button in VC1 and chooses the setting, this information should spread into all of the other VCs so that the button has the same background.
I am using storyboards, and I know that this is easily possible between 2VCs using segues, protocols, closures... I cannot find a proper way to spread information to more than 2VCs.
The only solution I can think of is usage of UserDefaults. I would save an information about a button setting and then call ViewWillAppear in each VC, where the background of the button would be set according to the value in UserDefaults. Is there a better solution, please?
EDIT:
As #cora mentioned in the comments, I was able to solve this using Notification Center.
You have several options, including:
Pass an array of the tab controllers to your "popup settings" controller and call a "settingSelected" func in each one directly.
Using Protocol / Delegate pattern, you could create an array of delegates in your "popup settings" controller.
You can use Notification Center.
You could subclass the button and use UIAppearance proxy.
Which approach to use will depend on a number of factors, based on exactly what all you need to do (are there other "settings"? or only that button background?)
You may want to search for swift using themes to see various different approaches.
“Is there a better solution, please?”
Not necessarily. Is this in fact a user default, to be preserved between launches? Then this is exactly what user defaults are for.
If not, then at least you need some central location where information about the current button color can be stored. An obvious candidate here is the tab bar controller itself. It gets notified every time there is a tab bar item switch, so it’s a perfect candidate.
Since you have mentioned you are using a UITabbarController, you can use an instance of UITabbarController and then access .viewControllers property of it and call their added public methods to get them triggered on events that you add. Additionally, using Notification Center makes more sense to me since your code will be more readable. Sometimes Notifications can just get a little confusing for new developers who are working on your code.

How to set a custom keyboard for UIWebView

How to show a custom keyboard and Input Accessory View for a editable UIWebView for iOS7 and up.
i.e: How can i set and make use a value from [UIWebView setInputView:] and [UIWebView setInputAccessoryView:]
It would be helpful to understand what you're trying to do? You can either be trying to force a specific type of keyboard such as numeric, email, etc. that will use the keyboard the user has explicitly installed on their device (or the system one).
In order to do this, you can reference this apple doc which shows you the 'type' attribute to add to an tag.
Otherwise you are asking about loading a custom keyboard that you have created from the webview. The app developer in me screams, "you should NEVER do this." If you're content is generic enough to merit putting into a webview, than it is certainly not worth loading a custom keyboard.
If you realllly need to do this, you can set keyboardDisplayRequiresUserAction to NO, then use custom javascript to request the app to perform a native function, then drop a uitextfield or uitextview directly overtop the html input field and set a custom input view on the native control. There are an obscene amount of problems with following this approach, and I sincerely hope you
Are you trying to customize the ios keyboard or you want to show an HTML keyboard?
In the first case you can look at this link: link
In the second case you can just google for it, this is the first result searching for "html keyboard".
Good luck
I believe there is no way to do this as of now. Hence, my current approach is to use a custom view below the keyboard and hide the keyboard and show the keyboard as required.

Popup notification box

Im trying to create a popup style notification, which is shown at the top of the screen (using a basic animation). The notification is going to be a simple form with a submit button.
Im trying to figure out how to go about this, and what are the best options i have. I've found this popup library: https://www.cocoacontrols.com/controls/cqmfloatingcontroller
What are the best options for 1. creating the popup and 2. animating to popup
If this is something that you will be reusing a lot, it might be worth subclassing UIAlertView, as you can then automatically use all "popup" methods provided by it,and by customizing it's view you can get the appearance you want.

AlertView with Checkbox Control in iOS

I want to display an alert view dialog in ios with usual title, message and two buttons + additionally I need a check box with message like "Always show this". In apple HIG document, they stated better to use an action sheet or view controller instead of displaying more controls in an alertview. Any alternative options are there?
Thanks in advance
You can create Custom View in which you can you all the required control and if you want to show the you can also use nice animation to show them and also you can set some good graphics as well. So the best way is to create CustomView.
All the best !!!

No need to save draft in MFMailComposeViewController

After clicking the cancel button of MFMailComposeViewController action sheet of save draft or not is generated.
I dont want this action sheet how can i achieve that?
thanks in advance.
From documentation
Important The mail composition interface itself is not customizable
and must not be modified by your application. In addition, after
presenting the interface, your application is not allowed to make
further changes to the email content. The user may still edit the
content using the interface, but programmatic changes are ignored.
Thus, you must set the values of content fields before presenting the
interface.
First line answers your question I think.

Resources