2017-08-28 49 views
2

我不知道这是可能的还是(更可能)有一个更好的方法来实现我的目标。在数组中添加一个按钮 - 斯威夫特

我已经使用的部分和项目编程创建一个实现代码如下:

let sections = ["One","Two","Three","Four"] 

let items = [["Text here"],["Text here"],[BUTTON HERE],["Text Here"]] 

我需要它加载外部网站的tableview内的按钮。

布局与此类似:

第一节

Lorem存有悲坐阿梅德,consectetur adipisicing ELIT,sed的根本eiusmod incididunt tempor UT labore等dolore麦格纳aliqua。请将您的评论发送给我们,我们会尽快为您解答。 Duis aute irure dolor in renhenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。 Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum。

Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。请将您的评论发送给我们,我们会尽快为您解答。 Duis aute irure dolor in renhenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。 Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum。

BUTTON给外部网站

Lorem存有悲坐阿梅德,consectetur adipisicing ELIT,sed的做eiusmod tempor incididunt UT labore等dolore麦格纳aliqua。请将您的评论发送给我们,我们会尽快为您解答。 Duis aute irure dolor in renhenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。 Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum。

它需要是一个按钮来支持我的用户体验研究。

如果按钮更容易,我会很高兴按钮出现在文本中,而不是单独的表格视图部分。

UPDATE: 从@vadian的合适的解决方案是使用这样的:

var string = "Google" 
var attributedString = NSMutableAttributedString(string: string, attributes:[NSLinkAttributeName: URL(string: "http://www.google.com")!]) 

yourTextView.attributedText = attributedString 

如何可以将其添加到数组?

+0

感谢您的期待,我真的很感激 – 128K

+1

您真的需要一个按钮吗? UITextView中没有足够的可点击链接吗?如果是的话,看看这个[问题](https://stackoverflow.com/questions/21629784/how-to-make-a-clickable-link-in-an-nsattributedstring-for-a) –

+1

你不能在数据源数组(**模型**)中使用*按钮*(a ** view **) – vadian

回答

1

将一个按钮添加到您的手机。使你的数组​​元素[字符串,布尔],并在你的tableview中,显示和隐藏基于数组的每个元素的布尔按钮。

+0

这是一个不错的选择。谢谢。有没有一个最佳的方式来实现这一目标?我刚刚在寻找例子。 – 128K

+1

从如何在tableView中实现自定义单元开始 - 这里有点超出范围,并且在很多示例中处理得比我能解释的要好。 – solenoid

+0

谢谢,我来看看 – 128K