- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 swift 的新手,问题是这个,是一个职业数据库,想要根据表中所选的职业加载类,这与代码中出现的链接有关,但万一连接不良,数组“Courses”在完成函数后加载,为此我想添加一句话以在数组未加载时保持函数运行,但我意识到事件指示器应该在数组加载时出现,实际上出现在函数的末尾,尽管我在函数的开头调用它,那么我的问题是如何使事件指示器出现,因为职业压在 table 上,直到“类(class)”数组加载职业的所有类(class)。请帮助我:(!这是代码...
[import UIKit
class CarreraTableViewController: UIViewController {
//Var to InicioApp ViewController
var CarreraSeleccionada = String()
//OK BarButton
@IBOutlet weak var Listo: UIBarButtonItem!
//Courses array
var Cursos = \[String\]()
//The Activity Indicator is in a UIView in the storyboard to more easily customize
@IBOutlet weak var ActivityIndicatorView: UIActivityIndicatorView!
@IBOutlet weak var ActivityContainer: UIView!
//Careers Array
var Carreras = \["Enlace Escolar - Antofagasta", "Enlace Escolar - Coquimbo", "Geología", "Ingeniería Civil Ambiental", "ICCI – Antofagasta", "ICCI – Coquimbo", "Ingeniería Civil", "Ingeniería Civil Industrial – Antofagasta", "Ingeniería Civil Industrial – Coquimbo", "Ingeniería Civil Metalúrgica", "Ingeniería Civil de Minas", "Ingeniería Civil Química", "Ingeniería en Construcción", "Ingeniería en Computación e Informática", "Ingeniería en Metalurgia", "Ingeniería en Procesos Químicos", "IPRYMA - Antofagasta", "IPRYMA - Coquimbo"\]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Carreras.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "MyCell"
let showData = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! CustomCellCarrera
let Carrera = Carreras\[indexPath.row\]
showData.CarreraLabel.text = Carrera
return showData
}
// Identifies which table row the user selected
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// ================= At this point I have my question, because ActivityContainer and ActivityIndicatorView does not appear until the end function
Listo.enabled = false
ActivityContainer.hidden = false
ActivityIndicatorView.startAnimating()
let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as! CustomCellCarrera
print(currentCell.CarreraLabel.text)
var arregloArea = \[String\]()
var arregloID = \[Int\]()
Cursos.removeAll()
var i = -1
if let CR = currentCell.CarreraLabel.text {
switch CR {
case "ICCI – Coquimbo":
i = 1
case "Ingeniería Civil Industrial – Coquimbo":
i = 2
case "ICCI – Antofagasta":
i = 10
case "Enlace Escolar - Antofagasta":
i = 15
case "Enlace Escolar - Coquimbo":
i = 14
case "Geología":
i = 16
case "Ingeniería Civil Ambiental":
i = 12
case "Ingeniería Civil":
i = 5
case "Ingeniería Civil Industrial – Antofagasta":
i = 4
case "Ingeniería Civil Metalúrgica":
i = 7
case "Ingeniería Civil de Minas":
i = 11
case "Ingeniería Civil Química":
i = 6
case "Ingeniería en Construcción":
i = 3
case "Ingeniería en Computación e Informática":
i = 13
case "Ingeniería en Metalurgia":
i = 17
case "Ingeniería en Procesos Químicos":
i = 18
case "IPRYMA - Antofagasta":
i = 8
case "IPRYMA - Coquimbo":
i = 9
default:
i = -1
}
}
//Varia i según carrera
let url = NSURL(string: "http://146.83.128.64/tongoy/g.php?&sala=-1&curso=-1&profesor=-1&semestre=-1&semestrec=-1&carrera=\(i)&area=-1")!
print(url)
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
if let urlContent = data {
do {
let jsonResult = try NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.MutableContainers)
for json in jsonResult as! Array<AnyObject> {
if let area = json\["area"\] as? String {
arregloArea.append(area)
} else {
}
if let id = json\["id"\] as? Int {
arregloID.append(id)
}else{
}
if let curso = json\["curso"\] as? String {
self.Cursos.append(curso)
}else{
}
}
} catch {
print("JSON serialization failed")
}
dump(self.Cursos)
}
}
task.resume()
CarreraSeleccionada = currentCell.CarreraLabel.text!
while Cursos.isEmpty{
}
if !Cursos.isEmpty{
Listo.enabled = true
ActivityIndicatorView.stopAnimating()
ActivityContainer.hidden = true
}
}
}
//To InicioApp VC
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
let DestViewController : InicioApp = segue.destinationViewController as! InicioApp
//Llamado a funcion de eliminar ramos duplicados
var RepCurso = removeDuplicates(Cursos)
RepCurso.sortInPlace(before)
print(RepCurso)
DestViewController.CursosCarrera = RepCurso
DestViewController.TableText = CarreraSeleccionada
}
func before(value1: String, value2: String) -> Bool {
// One string is alphabetically first.
// ... True means value1 precedes value2.
return value1 < value2;
}
func removeDuplicates(array: \[String\]) -> \[String\] {
var encountered = Set<String>()
var result: \[String\] = \[\]
for value in array {
if encountered.contains(value) {
// Do not add a duplicate element.
}
else {
// Add value to the set.
encountered.insert(value)
// ... Append the value.
result.append(value)
}
}
return result
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}][1]
最佳答案
您的循环 while Cursos.isEmpty{
将阻塞主线程,从而阻止对 UI 的任何更新。
您需要在完成闭包中执行所需的任务,而不是在函数末尾。另外,由于您正在更新 UI,因此需要将它们分派(dispatch)到主队列上,因为完成闭包将在另一个线程上执行。
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
if let urlContent = data {
do {
let jsonResult = try NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.MutableContainers)
for json in jsonResult as! Array<AnyObject> {
if let area = json\["area"\] as? String {
arregloArea.append(area)
} else {
}
if let id = json\["id"\] as? Int {
arregloID.append(id)
}else{
}
if let curso = json\["curso"\] as? String {
self.Cursos.append(curso)
}else{
}
}
} catch {
print("JSON serialization failed")
}
dispatch_async(dispatch_get_main_queue(), ^{
Listo.enabled = true
ActivityIndicatorView.stopAnimating()
ActivityContainer.hidden = true
});
dump(self.Cursos)
}
}
关于ios - 当使用 JSON 在后台加载数组并在 TableView 中进行选举时,事件指示器不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276747/
我正在对 tableView 是否呈现单元格进行单元测试。 我发现 tableView.cellForRow(at:) 返回 nil,而 tableView.dataSource?tableView(
我有 Tableview 用于显示客户下的食品订单。其中包含水平 UIStackview。在 UIStackView UIStackview 中很少有一/两行标签和一个用于显示订单项的UITableV
我有 Viewcontroller,我在其中设置了 ScrollView 。在 scrollview 中,我有一个 tableview,它位于 Container 中,就在容器下方,当我将 table
我想在滚动时让我的第一个单元格始终位于 tableview 的顶部。 任何帮助都是可观的。提前致谢... 最佳答案 这是为 UITableView 创建标题 View 的方法 - (UIView *)
在我的应用程序中,我点击一行,它会在其下方展开另一行。我想生成一种随机颜色,当我单击一行时,行背景会变成该颜色,而它下面的展开行会变成相同的颜色。如何让行生成相同的随机颜色? 我创建了一个函数来生成随
我正在为这个问题苦苦挣扎,所以我需要你的帮助。基本上我已经编写了一个复杂的 TableView Controller (使用 NSFetchedResults 协议(protocol)等)并且已经在我
我正在使用 JavaFx 2.2。我遇到了一个问题,我无法在 TableView 列中放置不同的组件。例如我有两列 1) 回答 2) 答案类型 如果 AnswerType 包含“Multiple Ch
试图弄清楚如何在 javafx 2 中禁用表列的重新排序? 最佳答案 这是解决方案: tblView.getColumns().addListener(new ListChangeListener()
我一直在寻找有关将数据刷新到 tableview 的信息。我试图直接修改模型,但我遇到了一个错误。我修改了模型,但表格没有刷新,只有当我移动一列时,表格才会显示修改后的值。 为了给你展示一个例子(13
给定一个TableView,我需要检测单元格上的双击。 tableView.setOnMouseClicked(new EventHandler() { @Override publi
我成功创建了一个 TableView,其中将特定列分配给了数据模型类。该程序可以将 csv 文件解析为其中并在表中正确显示所有内容。在此阶段,滚动不是问题。 然后我想选择特定行并将它们发送到另一个表。
我尝试了所有方法来用数据填充 TableView。下一个代码在表中插入一个新行,但数据没有出现在表中。我试图为此找到解释,但没有成功。 请帮忙。我不知道怎么了。 在 controller.java 中
我尝试了所有方法来用数据填充 TableView。下一个代码在表中插入一个新行,但数据没有出现在表中。我试图为此找到解释,但没有成功。 请帮忙。我不知道怎么了。 在 controller.java 中
我有一个通过 Tableview 显示玩家的应用程序。用户可以“添加”一个新玩家并输入他的姓名、高度、体重、图片等...保存后将被添加到 Tableview 中。他们还可以点击每个玩家,然后将他们带到
对于大学,我必须编写一个小应用程序,其想法是创建一个小公式集合。这个概念是有一个类别列表,选择类别后您会收到一个公式列表。选择所需的公式后,您将看到公式计算器的 View 。 我正在努力获得第一个UI
如果我只加载一个 TableView ,我的 View 中必须有两个 TableView ,它工作正常。但是当我尝试使用下面的方法加载两个表格 View 时,它给出了以下异常。 未捕获异常“NSRan
我是 JavaFx 的新手,我正在尝试创建一个 TableView ,而 fxml 是使用场景生成器创建的。如果我运行该程序,该表不会获取值。我发现这个问题在某种程度上符合我的要求( javaFX 2
是否可以对 tableView 进行反向排序?我搜索了很多解决方案,但没有任何效果。 效果就像whatsapp聊天。 一个普通的tableView是: ---------- label 1 -----
我有一个有趣的问题。我有两个 TableView ,一个在另一个里面。我有一个结构,我想用它来将数据添加到我的 TableView 中。该结构有 2 个字符串项和另一个具有 3 个字符串项的结构的数组
我正在使用的方法 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath
我是一名优秀的程序员,十分优秀!