xcode 如何使用 2 个视图从 IOS 应用程序发送电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9383367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:23:17  来源:igfitidea点击:

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

iosxcodeemailview

提问by Kris Hollenbeck

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?

我是一个 IOS 菜鸟,这可能是一个愚蠢的问题,所以就在这里。我有两种看法。视图 A 和视图 B。视图 A 有我的文本字段(用于我的消息),视图 B 有我的发送按钮。是否可以从视图 B 中的发送按钮发送在视图 A 中输入的文本?或者有没有更好的方法来做到这一点?

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).

基本上我想做的是使用菜单共享消息。用户单击发送消息后,将显示一个弹出窗口,询问用户如何发送。(IE:作为电子邮件发送、在 Twitter 上共享、在 Facebook 上共享或取消)。

My FIRST VIEW

我的第一眼

enter image description hereMy SECOND VIEWenter image description here

在此处输入图片说明我的第二个观点在此处输入图片说明

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.

也只是让我清楚。我不希望有人解决它,只是想知道以前是否有人做过这样的事情。如果您想提供可能的解决方案,那就太棒了。但实际上,或多或少,我正在寻找一些见解。

回答by StephenAshley.developer

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?"

问题:“是否可以从视图 B 中的发送按钮发送在视图 A 中输入的文本?或者有更好的方法吗?”

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."

回答:是的,这是可能的。这是一个教程,其中包含如何从应用程序发送电子邮件的说明:http: //blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/。在第一个视图的工具栏中,您可能会考虑使用标准系统图像 UIBarButtonSystemItemAction,而不是“发送消息”。您还可以考虑使用 UIActionSheet 而不是第二个视图。Apple 说,“使用 UIActionSheet 类向用户展示一组关于如何继续执行给定任务的备选方案。”

回答by Bill Bonar

Yes this is possible through several methods. The most OO and IMO the best way will be to create a custom initmethod on ViewB.

是的,这可以通过多种方法实现。最 OO 和 IMO 最好的方法是init在 ViewB 上创建自定义方法。

Something like -(id) initWithEmail(NSString* email, NSString* message)

就像是 -(id) initWithEmail(NSString* email, NSString* message)

回答by teriiehina

It is easy if all your widgets (the textfield, the button and the action sheet) are all ivars of the same view controller.

如果您的所有小部件(文本字段、按钮和操作表)都是同一个视图控制器的 ivars,则很容易。

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.

因此,在同一个控制器中,该按钮将触发 selectSendingMethod,该方法将显示弹出窗口,并且该表单的每个按钮都将调用适当的方法。

That should solve your problem.

那应该可以解决您的问题。