UITableView(Swift)中的MFMessageComposeViewController(MFMessageComposeViewController in a UITableView (Swift))
我正在尝试从自定义TableViewCell类中显示MFMessageComposeViewController,但我收到一条错误说:“UITableViewCell和UIViewController类的多重继承。” 我知道UIViewController是MFMessageComposeViewController所必需的,所以我该如何解决这个问题呢?
我的代码:
class TableViewCell: UITableViewCell, MFMessageComposeViewControllerDelegate { var userNumber: String! @IBAction func callButton(sender: AnyObject) { UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(userNumber)")!) } @IBAction func textButton(sender: AnyObject) { let message = MFMessageComposeViewController() message.body = "" message.recipients = ["\(userNumber)"] message.messageComposeDelegate = self } func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) { }
I'm trying to show an MFMessageComposeViewController from within a custom TableViewCell class but I get an error saying: "Multiple inheritance from classes UITableViewCell and UIViewController." I know that UIViewController is required for MFMessageComposeViewController, so how can I go about fixing this?
My code:
class TableViewCell: UITableViewCell, MFMessageComposeViewControllerDelegate { var userNumber: String! @IBAction func callButton(sender: AnyObject) { UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(userNumber)")!) } @IBAction func textButton(sender: AnyObject) { let message = MFMessageComposeViewController() message.body = "" message.recipients = ["\(userNumber)"] message.messageComposeDelegate = self } func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) { }
原文:https://stackoverflow.com/questions/31862286
满意答案
您可能需要为此推出自己的解决方案,如果您考虑它,这是有意义的。 通过隐藏两个字符的密码较弱但是显示三个字符的密码的视觉提示似乎暗示两个字符的密码就足够了。
那就是说你可以做的就是编写类似这样的hack:
<script language="javascript"> function onPasswordChange(textBox) { var passwordLabel = document.getElementById([labelID]); if(textBox.value.length < [constant]){ passwordLabel.style.display = 'none'; } else{ passwordLabel.style.display = 'inline'; } } </script>
然后,您可以附加此函数,控件
更改onKeyUp或onKeyDown事件,这样,如果密码字段的长度小于您希望的长度,它将隐藏包含未满足强度的消息的标签。 这是一个未经考验的唯一想法。 你最终可能会遇到与这个脚本冲突的工具包javascript的问题,但很难说。此外,labelID看起来是[controlIDName] _PasswordStrength。
编辑:
您可能希望将
onchangeonKeyUp或onKeyDown事件添加到您的控件中,如下所示(代码隐藏):
control.Attributes.Add(“onchange”,“onPasswordChange(this)”);control.Attributes.Add("onKeyDown", "onPasswordChange(this)");
编辑2:就黑客而言,这是非常混乱,但它的工作原理。 客户端:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:TextBox ID="password" runat="server"></asp:TextBox> <div id="PasswordStrengthContainer"></div> <asp:PasswordStrength ID="PS" runat="server" TargetControlID="password" DisplayPosition="RightSide" StrengthIndicatorType="Text" PreferredPasswordLength="10" PrefixText="Strength:" TextCssClass="TextIndicator_TextBox1" MinimumNumericCharacters="0" MinimumSymbolCharacters="0" RequiresUpperAndLowerCaseCharacters="false" TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" TextStrengthDescriptionStyles="cssClass1;cssClass2;cssClass3;cssClass4;cssClass5" CalculationWeightings="50;15;15;20" /> <script language="javascript"> function onPasswordChange(textBox) { var passwordLabel = document.getElementById("MainContent_password_PasswordStrength"); var container = document.getElementById("PasswordStrengthContainer"); if (passwordLabel != null) { document.getElementById("PasswordStrengthContainer").appendChild( document.getElementById("MainContent_password_PasswordStrength")); } if (textBox.value.length < 4) { container.style.display = 'none'; } else { container.style.display = 'inline'; } } </script>
服务器端:
password.Attributes.Add("onKeyDown", "onPasswordChange(this)"); password.Attributes.Add("onBlur", "onPasswordChange(this)");
此代码效率不高,可以清理,但可用于演示目的。 javascript函数非常基本但是你会注意到这一行:
if (passwordLabel != null) { document.getElementById("PasswordStrengthContainer").appendChild( document.getElementById("MainContent_password_PasswordStrength")); }
不幸的是,工具包javascript函数将在您的函数之后触发,因此工具包会将显示设置为“无”。 这段代码的作用是从页面中删除标签并将其放在div中,然后我们只将div的display属性设置为any,这将有效地隐藏标签。 但是有一个单一的错误:当按下退格键删除字符时,div在某些情况下不会消失。 我没有时间来追查这个问题,但要清除它应该是微不足道的。
另外我在Chrome中的onChange遇到了一些问题,因此选择onKeyDown而不是上面指出的@Adriano。
You are probably going to need to roll your own solution for this which makes sense if you think about it. By hiding the visual cue that a password of two characters is weak but displaying it for a password of three characters would seem to imply that the two character password is sufficient.
That being said what you might be able to do is write some sort of hack similar to this:
<script language="javascript"> function onPasswordChange(textBox) { var passwordLabel = document.getElementById([labelID]); if(textBox.value.length < [constant]){ passwordLabel.style.display = 'none'; } else{ passwordLabel.style.display = 'inline'; } } </script>
You could then attach this function the controls
changeonKeyUp or onKeyDown event so that if the length of the password field was less than what you want it to be it will hide the label that contains the message that the strength has not been met. This is untested an only a thought. You may wind up with issue from the toolkit javascript colliding with this script but it is tough to say.Additionally the labelID looks to be [controlIDName]_PasswordStrength.
Edit:
You would probably want to add the
onchangeonKeyUp or onKeyDown event to your control like so (code behind):
control.Attributes.Add("onchange", "onPasswordChange(this)");control.Attributes.Add("onKeyDown", "onPasswordChange(this)");
Edit 2: As far as hacks go this is pretty messy but it works. Clientside:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:TextBox ID="password" runat="server"></asp:TextBox> <div id="PasswordStrengthContainer"></div> <asp:PasswordStrength ID="PS" runat="server" TargetControlID="password" DisplayPosition="RightSide" StrengthIndicatorType="Text" PreferredPasswordLength="10" PrefixText="Strength:" TextCssClass="TextIndicator_TextBox1" MinimumNumericCharacters="0" MinimumSymbolCharacters="0" RequiresUpperAndLowerCaseCharacters="false" TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" TextStrengthDescriptionStyles="cssClass1;cssClass2;cssClass3;cssClass4;cssClass5" CalculationWeightings="50;15;15;20" /> <script language="javascript"> function onPasswordChange(textBox) { var passwordLabel = document.getElementById("MainContent_password_PasswordStrength"); var container = document.getElementById("PasswordStrengthContainer"); if (passwordLabel != null) { document.getElementById("PasswordStrengthContainer").appendChild( document.getElementById("MainContent_password_PasswordStrength")); } if (textBox.value.length < 4) { container.style.display = 'none'; } else { container.style.display = 'inline'; } } </script>
Serverside:
password.Attributes.Add("onKeyDown", "onPasswordChange(this)"); password.Attributes.Add("onBlur", "onPasswordChange(this)");
This code is not efficient and could be cleaned up but works for demonstrative purposes. The javascript function is pretty basic however you will notice this line:
if (passwordLabel != null) { document.getElementById("PasswordStrengthContainer").appendChild( document.getElementById("MainContent_password_PasswordStrength")); }
Unfortunately the toolkits javascript functions will fire AFTER your function so setting the display to 'none' is wiped out by the toolkit. what this code does is remove the label from the page and places it in the div then we merely set the display property of our div to whatever and that will effectively hide the label. There is a singular bug though: when hitting backspace to delete characters the div doesn't disappear in certain instances. I don't really have time to track down the issue but it should be trivial for you to clear it up.
Additionally I was having some problems with onChange in Chrome so opted for onKeyDown instead as @Adriano pointed out above.
相关问答
更多jQuery密码强度检查器(jQuery password strength checker)
检查密码的最佳方法是什么?(What is the best way to check the strength of a password?)
密码强度正则表达式与数字[重复](Password strength regex with numbers [duplicate])
使用密码强度检查的jQuery表单验证(jQuery form validation with password strength check)
密码符号,长度和'强度'(Password symbols, length and 'strength')
Python密码强度[重复](Python password strength [duplicate])
如何在最小字符后检查密码强度?(How to check password strength only after min characters?)
在密码强度检查器中使用一组不可用的单词(Using an array of unusable words in a password strength checker)
密码强度检查器(Password Strength Checker)
如何让我的程序返回密码强度(How can i get my program to return the password strength)
相关文章
更多UITableView 顶部能够放大的图片
Swift入门视频教程-尚学堂视频教程
千锋首发Swift视频教程
ServletOutputStream cannot be resolved to a type
HTML 超链接(a标签、锚)
Securing Solr on Tomcat access using a user account
[译文] 恶意软件行为综述 - A View on Current Malware Behaviors
Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
pychseg - A Python Chinese Segment Project - Google Project Hosting
Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!