我有我的应用程序的一部分,这个实施后:无法从视图去另一个做一些说明
为什么当我点击“CERCA每ISBN”按钮,它进入的tableView没有做我写的说明?
这是“CERCA每ISBN”按钮的代码,我点击:
@IBAction func ISBNButtonClick(_ sender: Any) {
let libro = Libro.text! as String
if Libro.text!.isEmpty {
//Alert per segnalare i campi mancanti, oltre a caselle rosse
var myAlert = UIAlertController(title:"Attenzione\n", message:"Inserire il codice ISBN", preferredStyle:UIAlertControllerStyle.alert);
let okAction = UIAlertAction(title:"Ok", style:UIAlertActionStyle.default){ action in }
myAlert.addAction(okAction);
self.present(myAlert, animated:true, completion:nil);
// placeholder rosso se la text è vuota
Libro.attributedPlaceholder = NSAttributedString(string:"Digita qui...", attributes: [NSForegroundColorAttributeName: UIColor.red])
//se tutti i campi obbligatori sono stati inseriti, proseguo ad altri controlli
}else{
if(isNumeric(string: libro)){
if((libro.characters.count) < 13 || (libro.characters.count) > 13){
//Alert per segnalare l'ISBN più corto di 13 numeri
var myAlert = UIAlertController(title:"Attenzione\n", message:"L'ISBN deve essere di 13 cifre", preferredStyle:UIAlertControllerStyle.alert);
let okAction = UIAlertAction(title:"Ok", style:UIAlertActionStyle.default){ action in }
myAlert.addAction(okAction);
self.present(myAlert, animated:true, completion:nil);
}else{
//inviare dati al server
let myUrl = NSURL(string:"http://chuadiv.ddns.net/easytoschool/fetch_book_detailed.php");
let request = NSMutableURLRequest(url:myUrl as! URL);
request.httpMethod = "POST";
let postString = "name=\(libro)&mail=\(UserDefaults.standard.object(forKey: "userEmail") as? String)";
request.httpBody = postString.data(using: String.Encoding.utf8);
let task = URLSession.shared.dataTask(with: request as URLRequest){
data, response, error in
if error != nil{
print("error=\(error)")
return
}
var err: NSError?
do{
var json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSArray
if let parseJSON: NSArray = json{
for index in 0...parseJSON.count-1 {
print("ciao")
let libro = parseJSON[index] as! [String:Any]
print("\n\n",index,":\n")
let book = resultCell.init(bookId: libro["id"] as! String,bookName: libro["name"] as! String,bookAuthor: libro["author"] as! String,bookSchool: libro["school"] as! String,bookPrice: libro["price"] as! String,bookStatus: libro["status"] as! String,bookISBN: libro["isbn"] as! String,bookType: libro["type"] as! String,bookIdSeller: libro["idSeller"] as! String,bookNameSeller: libro["nameSeller"] as! String,bookSurnameSeller: libro["surnameSeller"] as! String)
book.printBook();
HomeViewController.booksArray.append(book)
}
}
}catch{
print("error=\(error)")
return
}
}
task.resume();
performSegue(withIdentifier: "homeToListBook", sender: self)
}
}else{
var myAlert = UIAlertController(title:"Attenzione\n", message:"Inserire solo numeri per la ricerca attraverso codice ISBN", preferredStyle:UIAlertControllerStyle.alert);
let okAction = UIAlertAction(title:"Ok", style:UIAlertActionStyle.default){ action in }
myAlert.addAction(okAction);
self.present(myAlert, animated:true, completion:nil);
}
}
}
我想,当我按下按钮,设置我的数组并把它转到的tableView后,但我可以“T
我写了你的代码部分,但它不起作用。它会立即转到另一个视图而不打印“if part” – Marco
在另一个视图中,我想先打印数组,但它告诉“索引超出范围”;我认为这是因为它立即进入视图没有设置数组 – Marco
而我在我的应用的另一部分有这种错误 – Marco