首页
\
问答
\
以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
我必须确保我可以点击“隐私”一词来打开网页链接。 我尝试了我发现的建议,但他们都是旧事物,他们似乎不再工作了......我不知道我该如何解决问题
private lazy var firstTermDescriptionLabel: UILabel = { let label = UILabel(frame: .zero) let firstTermsMessage = "I Agree to the License Terms and Privacy Policy" var attributedString = NSMutableAttributedString.init(string: "Privacy") attributedString.addAttribute(.link, value: "https://www.google.com/url?q=https://www.iubenda.com/privacy-policy/58446596&sa=D&source=hangouts&ust=1528787597335000&usg=AFQjCNEPkofPxSm7TDRMvxjOjCz5cio27w", range: NSRange(location: 0, length: 7)) label.isUserInteractionEnabled = true label.text = firstTermsMessage label.font = UIFont.systemFont(ofSize: 13, weight: .regular) label.textAlignment = .left label.numberOfLines = 0 label.translatesAutoresizingMaskIntoConstraints = false label.heightAnchor.constraint(equalToConstant: 36).isActive = true return label }()
I have to make sure that I can click on the word "Privacy" in order to open a web link. I tried with the suggestions that I found but they are old things and they do not seem to work anymore .. I do not know how I can solve the problem
private lazy var firstTermDescriptionLabel: UILabel = { let label = UILabel(frame: .zero) let firstTermsMessage = "I Agree to the License Terms and Privacy Policy" var attributedString = NSMutableAttributedString.init(string: "Privacy") attributedString.addAttribute(.link, value: "https://www.google.com/url?q=https://www.iubenda.com/privacy-policy/58446596&sa=D&source=hangouts&ust=1528787597335000&usg=AFQjCNEPkofPxSm7TDRMvxjOjCz5cio27w", range: NSRange(location: 0, length: 7)) label.isUserInteractionEnabled = true label.text = firstTermsMessage label.font = UIFont.systemFont(ofSize: 13, weight: .regular) label.textAlignment = .left label.numberOfLines = 0 label.translatesAutoresizingMaskIntoConstraints = false label.heightAnchor.constraint(equalToConstant: 36).isActive = true return label }()
原文:https://stackoverflow.com/questions/50793833
更新时间:2024-04-25 16:04
最满意答案
EXCEPTION
子句需要与异常处于同一个块中。例如:
CREATE OR REPLACE FUNCTION test_excep (arg integer) RETURNS integer AS $func$ DECLARE res INTEGER; BEGIN res := 100 / arg; RETURN res; EXCEPTION WHEN division_by_zero THEN RETURN 999; END $func$ LANGUAGE plpgsql;
The
EXCEPTION
clause needs to be in the same block as the exception.For instance:
CREATE OR REPLACE FUNCTION test_excep (arg integer) RETURNS integer AS $func$ DECLARE res INTEGER; BEGIN res := 100 / arg; RETURN res; EXCEPTION WHEN division_by_zero THEN RETURN 999; END $func$ LANGUAGE plpgsql;
相关问答
更多-
这是一个非常全面的指导,我认为是必读: 异常和错误处理 - C ++常见问题或C ++常见问题 作为一般的经验法则,当您的程序可以识别出阻止执行的外部问题时,抛出异常。 如果您从服务器接收数据,并且数据无效,则抛出异常。 磁盘空间不足? 抛出异常 宇宙射线阻止您查询数据库? 抛出异常 但是如果您从自己的程序中获取一些无效数据 - 不要抛出异常。 如果你的问题来自你自己的坏代码,最好使用ASSERT来防范它。 需要异常处理来识别程序无法处理的问题,并告诉他们有关用户的问题,因为用户可以处理它们。 但程序中的错 ...
-
我如何让python函数返回异常回溯或结果?(How do I have a python function return an exception traceback, or the result?)[2022-02-09]
我建议,不要在此方法中捕获异常,而是让它引发异常并从您调用的任何地方捕获它。 换句话说,不要把你的try catch放在那个方法中。 将try catch放在调用该方法的任何地方,并捕获它可以提升的内容。 所以,请改为: import traceback def ReadFile(): with open("/etc/passwd") as file: data = file.read() return data try: r = ReadFile() excep ... -
有几种方法可以解决这个问题。 第一种是更改返回函数的返回类型,而不是通过值返回类,通过std::unique_ptr传递它。 std::unique_ptr可以为null,因此如果有异常,则可以返回null unique_ptr否则只需将unique_ptr返回给您创建的对象。 另一种选择是使用boost::optional或std::optional 。 您现在可以使用boost::optional但std::optional是C ++ 17的功能,因此它的可用性有限。 就个人而言,我更喜欢可选方法,因为 ...
-
来自GetEval的selenium文档 : 获取评估指定JavaScript代码段的结果。 代码段可能有多行,但只会返回最后一行的结果。 因此,您只需要return : string code = selenium.GetEval( "var win = this.browserbot.getUserWindow(); "+ "win.editAreaLoader.GetValue(win.loadedCodeEditorID);" ); From the selenium document ...
-
将我的评论转换为答案: 你应该使用像: def retry(function): @wraps(function) def _retry(*args, **kwargs): try: reply = function(*args, **kwargs) print "reply: ", reply return reply except PDError as msg: ...
-
EXCEPTION子句需要与异常处于同一个块中。 例如: CREATE OR REPLACE FUNCTION test_excep (arg integer) RETURNS integer AS $func$ DECLARE res INTEGER; BEGIN res := 100 / arg; RETURN res; EXCEPTION WHEN division_by_zero THEN RETURN 999; END $func$ LANGUAGE plpg ...
-
使用TRY_CONVERT而不是CONVERT ,这将是: CREATE FUNCTION TEST(@date varchar(50)) RETURNS DATETIME AS BEGIN RETURN TRY_CONVERT(DATETIME, @date) END 结果: select [dbo].[TEST]('20171201') --output:2017-12-01 00:00:00.000 select [dbo].[TEST]('9999999999') --output: ...
-
如果抛出异常,则使extern C ++函数返回消息(Make extern C++ function return a message if an exception is thrown)[2023-02-21]
让您的函数返回BOOL ,并将错误消息字符串作为参数,例如: BOOL Calculate(double &result, double a, double b, char *pMsg, size_t nMsgSize) { try { result = InternalCalculation(a, b); } catch(std::invalid_argument& e) { strncpy_s(pMsg, nMsgSize, e.what(), _TRUNCA ... -
这是你应该处理的......我在你的代码中添加了'return -1'。 HTH。 create or replace FUNCTION f_interestrate(pn_principal NUMBER, pn_interest NUMBER, pn_years NUMBER) RETURN NUMBER IS vn_interestrate NUMBER; ex_invalid_devisor EXCEPTION; BEGIN IF pn_principa ...
-
这似乎有效: function functionWhichCreatesOutputThenCausesAnException() { "hello" 1/0 "world" } try { $result = @() functionWhichCreatesOutputThenCausesAnException | foreach {$result += $_} } catch { $($error[0]) } This seems to work: ...