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
2022-07-29 09:07

满意答案

您可能需要为此推出自己的解决方案,如果您考虑它,这是有意义的。 通过隐藏两个字符的密码较弱但是显示三个字符的密码的视觉提示似乎暗示两个字符的密码就足够了。

那就是说你可以做的就是编写类似这样的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。

编辑:

您可能希望将 onchange onKeyUp或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 change onKeyUp 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 onchange onKeyUp 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)

最好的方法是采用TJB建议的现有插件。 至于你对代码本身的问题,一个更好的方法就是这样写: var pass = "f00Bar!"; var strength = 1; var arr = [/.{5,}/, /[a-z]+/, /[0-9]+/, /[A-Z]+/]; jQuery.map(arr, function(regexp) { if(pass.match(regexp)) strength++; }); (修改以纠正语法错误。) The best way is to...

检查密码的最佳方法是什么?(What is the best way to check the strength of a password?)

根据语言,我通常使用正则表达式来检查它是否具有: 至少有一个大写字母和一个小写字母 至少一个数字 至少一个特殊字符 长度至少六个字符 您可以要求以上所有的,或使用强度计类型的脚本。 对于我的力量计,如果密码的长度是正确的,那么它的评估如下: 一个条件满足:弱密码 两个条件满足:中等密码 所有条件满足:强密码 您可以调整以上以满足您的需求。 1: Eliminate often used passwords Check the entered passwords against a list of ...

密码强度正则表达式与数字[重复](Password strength regex with numbers [duplicate])

看看下面的代码,它使用test返回一个布尔密码是否包含大写和小写。 你会看到它如何测试各种密码的正则表达式。 var upperCase= new RegExp('[A-Z]'); var lowerCase= new RegExp('[a-z]'); function test(password) { return [ upperCase.test(password), lowerCase.test(password)]; } conso...

使用密码强度检查的jQuery表单验证(jQuery form validation with password strength check)

您可以根据状态栏使用按钮的禁用启用,轻松快速解决问题,但我相信如果您想使它更通用和坚实,您可以依赖于设置为false的标志,如果验证脏或仅将其切换为true如果验证行为符合您的要求 $(document).ready(function(){ $('#password').keyup(function(){ var valid = true; $('#result').html(checkStrength($('#password').val())); ...

密码符号,长度和'强度'(Password symbols, length and 'strength')

1)破解密码不需要一次发生。 一个很好实施的暴力破解可能会首先通过小范围的角色进行迭代,然后进入帽和数字。 从最简单的范围开始(也许只是小写的az)将找到那些不幸构造了弱密码的密码。 他们也可能从字典攻击或最常用密码使用的攻击开始,因为它们只需要很少的时间。 2)饼干不会通过一些在线服务的登录提示进行暴力破解。 任何真正意图访问帐户的人都会检索用户密码的散列并在自己的机器上破解它,而不是通过互联网。 虽然散列密码的方法实际上是无限的,但有一些非常常见的方法可以通过诸如散列字符长度之类的属性来识别。...

Python密码强度[重复](Python password strength [duplicate])

对我来说,正则表达式绝对是解决这个问题的最简单方法。 给出一个密码password示例,你检查它的方式是: import re # Check if contains at least one digit if re.search(r'\d', password): print "Has a digit" # Check if contains at least one uppercase letter if re.search(r'[A-Z]', password): print...

如何在最小字符后检查密码强度?(How to check password strength only after min characters?)

您可能需要为此推出自己的解决方案,如果您考虑它,这是有意义的。 通过隐藏两个字符的密码较弱但是显示三个字符的密码的视觉提示似乎暗示两个字符的密码就足够了。 那就是说你可以做的就是编写类似这样的hack: <script language="javascript"> function onPasswordChange(textBox) { var passwordLabel = document.getElementById([labelID]); if(textBox....

在密码强度检查器中使用一组不可用的单词(Using an array of unusable words in a password strength checker)

我实际上已经建立了自己的,因为我不需要力量计; 只是一个需求检查器。 通过使用正则表达式使用简单的password.match,我能够检查这些特定的单词。 给我的要求没有指定大写或小写字母,所以我做了一个简单的匹配。 password.match(/((SYSTEM)|(Password)|(Default)|(USER)|(Demo)|(TEST))/) 我还能够使用不同的算法检查以下内容。 //password != user name, first name, or last name...

密码强度检查器(Password Strength Checker)

您已为span元素的id提供了颜色.Id属性的优先级高于class属性,因此颜色不会分配给结果。 您可以将类添加到<span>元素并为该类提供颜色。 你可以在这里看到演示http://jsfiddle.net/tenigada/RH8f6/575/ You have provided color to id of span element.Id attribute has an highest priority than class attribute so the color is not as...

如何让我的程序返回密码强度(How can i get my program to return the password strength)

首先,你告诉python打印函数,而不是函数的评估。 这就是你得到那条信息的原因。 此外,您永远不会调用您编写的任何功能。 在声明所有定义之后获得工作程序如下: 调用check_len定义: strength = check_len(password) 但是,该定义不会返回任何值。 您可以将其更改为: def check_len(password): l = len(password) if 6 < l < 16: x = check_char(password,...

相关文章

更多

UITableView 顶部能够放大的图片

UITableView 顶部能够放大的图片 现在有挺多的应用在 UITableView 顶部加入图片 ...

Swift入门视频教程-尚学堂视频教程

最新Swift语言语法介绍,包括Swift流程控制语句、Swift各种构造函数、closure、泛型、 ...

千锋首发Swift视频教程

千锋Swift视频教程-7.Swift结构体.mp4 千锋Swift视频教程-13.代理反向传值.mp ...

ServletOutputStream cannot be resolved to a type

在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec ...

HTML 超链接(a标签、锚)

a标签: anchor锚 1.超链接 -&gt; 点击之后跳转页面 格式: 协 ...

Securing Solr on Tomcat access using a user account

Open [Tomcat install dir]\tomcat-users.xmlfor editi ...

[译文] 恶意软件行为综述 - A View on Current Malware Behaviors

A View on Current Malware Behaviors Ulrich Bayer ...

Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing

http://spark-project.org/ 项目首页 http://shark.cs.berk ...

pychseg - A Python Chinese Segment Project - Google Project Hosting

pychseg - A Python Chinese Segment Project - Google ...

Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years

这篇文件写的非常好,推荐大家重温一下: http://highscalability.com/blog ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本