作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 tableView,当用户单击单元格时,每个单元格应该打开不同的 URL
代码如下:
var mathLessons = [["1"],["2"],["3"],["4"]]
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.textLabel?.text = lessons.mathLessons[indexPath.section][indexPath.row]
return cell
}
最佳答案
使用自定义结构来保存类(class)编号和相应的 URL
struct Lesson {
let number : String
let url : URL
}
var mathLessons = [Lesson(number: "1", url: URL(string:"https://...1")!),
Lesson(number: "2", url: URL(string:"https://...2")!),
Lesson(number: "3", url: URL(string:"https://...3")!),
Lesson(number: "4", url: URL(string:"https://...4")!)]
在cellForRow
中显示数字
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.textLabel?.text = lessons.mathLessons[indexPath.section][indexPath.row].number
return cell
}
在didSelect
中打开对应的URL
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let url = lessons.mathLessons[indexPath.section][indexPath.row].url
UIApplication.shared.open(url)
}
关于ios - 我想将每个单元格链接到不同的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51555335/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!