- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常奇怪的错误,这个应用程序中的应用程序使用模态视图 Controller ,在 View 中我使用 UIPickerView
来显示名称。值应该显示在 RisorseUmaneUIPicker
中!奇怪的是,一切正常,但有时当您在 3g 移动设备上向应用程序发送短信时,UIPickerView
仍为空。我该如何解决这个问题?
我用postman检查了json请求,它总是正确的
查看:
class RisorseUmaneViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDelegate, UITableViewDataSource {
//Dichiarazione Oggetti
//L'array User contiene le informazione su tutti gli utenti presenti nel database
private var UserLoad: [UserStruct] = []
private var RisorseUmaneUIPicker: UIPickerView = UIPickerView()
private let datePicker: UIDatePicker = UIDatePicker()
private let StartPicker: UIDatePicker = UIDatePicker()
private let EndPicker: UIDatePicker = UIDatePicker()
private let PausaPicker: UIDatePicker = UIDatePicker()
private var textView: UITextView = UITextView()
private var RisoseUmaneTableView: UITableView!
private var RisorseUmaneLoad: [RisorsaUmanaStruct] = []
private var SwitchRapportino: UISwitch = UISwitch()
//L'oggetto RisorsaUmana Rappresenta la risorsa che verrà inserita
public var Cantiere: Cantiere
private var RisorsaSelezionata: RisorsaUmana?
private var Extensioni: Extend = Extend()
public var Stato: String = "Inserimento"
private var RisorsaRapportino: Bool = false;
init(CantiereInterno: Cantiere) {
self.Cantiere = CantiereInterno
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
hideKeyboardWhenTappedAround()
self.view.backgroundColor = UIColor.white
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationItem.title = "Risorse Umane"
InitRisorseUmaneViewController();
//Modifica UiPickerView delle Risorse con l'utente che ha effettuato il login
print("Login di : \(UserLoginDefault.Username)")
selectPicker(withText: UserLoginDefault.Username)
}
//Funzione di Configurazione Iniziale della View
private func InitRisorseUmaneViewController() {
//inizializzo il Cantiere
let displayWidth: CGFloat = self.view.frame.width
//Carico le Risorse
CaricaRisorse()
//Configurazione Label Risorsa
let label = UILabel(frame: CGRect(x: (self.view.frame.width / 2) - 150, y: 65, width: 90, height: 24))
label.font = UIFont(name: "HelveticaNeue-Bold", size: 16.0)
label.textAlignment = .center
label.text = "Risorsa: "
self.view.addSubview(label)
//Configurazione :impostazioni picker view
self.RisorseUmaneUIPicker = UIPickerView(frame: CGRect(x: (self.view.frame.width / 2) - 70, y: 50, width: 200, height: 50))
self.RisorseUmaneUIPicker.delegate = self
self.RisorseUmaneUIPicker.dataSource = self
self.RisorseUmaneUIPicker.backgroundColor = UIColor.white
self.view.addSubview(RisorseUmaneUIPicker)
//Configuro il DataTime Picker per la data
self.datePicker.frame = CGRect(x: 10, y: 100, width: self.view.frame.width, height: 80)
self.datePicker.timeZone = NSTimeZone.local
self.datePicker.backgroundColor = UIColor.white
self.datePicker.datePickerMode = UIDatePickerMode.date;
//Aggiunto un evento quando viene modificato il valore del datePicker
self.datePicker.addTarget(self, action: #selector(RisorseUmaneViewController.datePickerValueChanged(_:)), for: .valueChanged)
self.view.addSubview(datePicker)
//Congiurazione Ore di Inizio e Fine
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
let dateStart = dateFormatter.date(from: "08:00")
let dateEnd = dateFormatter.date(from: "17:30")
let datePausa = dateFormatter.date(from: "01:30")
//Configuro il DataPicker di Start
self.StartPicker.frame = CGRect(x: (self.view.frame.width / 2) - 90, y: 190, width: 100, height: 40)
self.StartPicker.timeZone = NSTimeZone.local
self.StartPicker.backgroundColor = UIColor.white
self.StartPicker.datePickerMode = UIDatePickerMode.time
self.StartPicker.date = dateStart!
self.StartPicker.addTarget(self, action: #selector(RisorseUmaneViewController.SetDataInizio(sender:)), for: .valueChanged)
self.StartPicker.minuteInterval = 30
self.view.addSubview(StartPicker)
//Configuro il DataPicker di End
self.EndPicker.frame = CGRect(x: (self.view.frame.width / 2) + 60, y: 190, width: 100, height: 40)
self.EndPicker.timeZone = NSTimeZone.local
self.EndPicker.backgroundColor = UIColor.white
self.EndPicker.datePickerMode = UIDatePickerMode.time
self.EndPicker.date = dateEnd!
self.EndPicker.addTarget(self, action: #selector(RisorseUmaneViewController.SetDataFine(sender:)), for: .valueChanged)
self.EndPicker.minuteInterval = 30
self.view.addSubview(EndPicker)
//Configuro il DataPicker di Pausa
self.PausaPicker.frame = CGRect(x: (self.view.frame.width / 2) - 30, y: 250, width: 100, height: 40)
self.PausaPicker.timeZone = NSTimeZone.local
self.PausaPicker.backgroundColor = UIColor.white
self.PausaPicker.datePickerMode = UIDatePickerMode.time
self.PausaPicker.date = datePausa!
self.PausaPicker.addTarget(self, action: #selector(RisorseUmaneViewController.SetPausa(sender:)), for: .valueChanged)
self.PausaPicker.minuteInterval = 30
self.view.addSubview(PausaPicker)
//Configurazione Testo TextView
self.textView = UITextView(frame: CGRect(x: 0, y: 300, width: displayWidth, height: 85))
self.automaticallyAdjustsScrollViewInsets = false
textView.font = UIFont(name: "HelveticaNeue-Bold", size: 18.0)
textView.textAlignment = NSTextAlignment.justified
textView.textColor = UIColor.blue
textView.backgroundColor = UIColor.lightGray
self.view.addSubview(textView)
//Bottone per inserimento:
let ImageInserisci = UIImage(named: "inserisci.png") as UIImage?
let ButtonInserisciRisorsaUmana = UIButton()
ButtonInserisciRisorsaUmana.frame = CGRect(x: (self.view.frame.width / 2) - 180, y: 395, width: 80, height: 80)
ButtonInserisciRisorsaUmana.setImage(ImageInserisci, for: .normal)
ButtonInserisciRisorsaUmana.setTitleColor(UIColor.black, for: .normal)
ButtonInserisciRisorsaUmana.set(image: ImageInserisci, attributedTitle: NSAttributedString(string: "Inserisci"), at: UIButton.Position(rawValue: 1)!, width: 30, state: UIControlState.normal)
ButtonInserisciRisorsaUmana.addTarget(self, action: #selector(InserisciRisorsaButtonAction), for: .touchUpInside)
self.view.addSubview(ButtonInserisciRisorsaUmana)
//Bottone per tornare a schermata principale
let ImageReturn = UIImage(named: "return.png") as UIImage?
let buttonReturn = UIButton()
buttonReturn.frame = CGRect(x: (self.view.frame.width / 2) - 30, y: 395, width: 80, height: 80)
buttonReturn.backgroundColor = UIColor.white
buttonReturn.setImage(ImageReturn, for: .normal)
buttonReturn.setTitle("Go Home", for: .normal)
buttonReturn.addTarget(self, action: #selector(Return), for: .touchUpInside)
self.view.addSubview(buttonReturn)
//Configuro lo UISwitch per l'inserimento delle risorse nel cantiere
let labelRapportino = UILabel(frame: CGRect(x: (self.view.frame.width / 2) + 80, y: 395, width: 130, height: 21))
labelRapportino.text = "Rapportino?"
labelRapportino.font = UIFont(name: "HelveticaNeue-Bold", size: 16.0)
self.view.addSubview(labelRapportino)
SwitchRapportino = UISwitch(frame: CGRect(x: (self.view.frame.width / 2) + 100, y: 430, width: 0, height: 0))
SwitchRapportino.setOn(false, animated: true)
SwitchRapportino.addTarget(self, action: #selector(RisorseUmaneViewController.switchValueDidChange(sender:)), for: .valueChanged)
self.view.addSubview(SwitchRapportino)
//Stato Inserimento: l'utente sta inserendo delle risorse dentro una cantier
if(Stato == "Inserimento") {
RisorsaSelezionata = RisorsaUmana(CantiereInterno: Cantiere)
//Configurazione table view
RisoseUmaneTableView = UITableView(frame: CGRect(x: 0, y: 500, width: displayWidth, height: self.view.frame.height - 500))
RisoseUmaneTableView.register(CustomTableViewCellArticolo.self, forCellReuseIdentifier: "MyCell")
RisoseUmaneTableView.dataSource = self
RisoseUmaneTableView.delegate = self
RisoseUmaneTableView.tableFooterView = UIView()
RisoseUmaneTableView.rowHeight = 60
RisoseUmaneTableView.layer.borderWidth = 2.0
self.view.addSubview(RisoseUmaneTableView)
//Carica Le risorse Umane e chiamo i Metodi di configurazione
CaricaRisorseCantiere()
}
SetPausa(sender: PausaPicker)
SetDataInizio(sender: StartPicker)
SetDataFine(sender: EndPicker)
datePickerValueChanged(datePicker)
SwitchRapportino.isHidden = false
labelRapportino.isHidden = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func selectPicker(withText text: String) {
print("Testo: \(text)")
if let index = self.UserLoad.index(where: { $0.Username == text }) {
print("Indice di riga: \(index)")
RisorseUmaneUIPicker.selectRow(index, inComponent: 0, animated: true)
self.RisorseUmaneUIPicker.reloadAllComponents()
}
else {
print("text not found")
}
}
//Funzione per il caricamento delle risorse Umane
func CaricaRisorse() {
DispatchQueue.global(qos: .userInteractive).async {
let rtemp = User()
rtemp.CaricaUtenti(completion: { result in
self.UserLoad = result
self.RisorseUmaneUIPicker.reloadAllComponents()
});
}
}
@objc func SetPausa(sender: UIDatePicker) {
RisorsaSelezionata?.SetOrePausa(Pausa: Extensioni.CastFromDateToString_SqlServer_Pausa(mydate: PausaPicker.date))
}
@objc func SetDataFine(sender: UIDatePicker) {
RisorsaSelezionata?.SetOreFine(OreFine: Extensioni.CastFromDateToString_SqlServer_DateTime(mydate: EndPicker.date))
}
@objc func SetDataInizio(sender: UIDatePicker) {
RisorsaSelezionata?.SetOreInizio(OreInizio: Extensioni.CastFromDateToString_SqlServer_DateTime(mydate: StartPicker.date))
}
@objc func InserisciRisorsaButtonAction(sender: UIButton!) {
print("\n Id Risorsa: \(String(describing: RisorsaSelezionata?.GetIdUtente()))")
if(textView.text.isEmpty || RisorsaSelezionata?.GetIdUtente() == 0) {
let alertController = UIAlertController(title: title, message: "Attenzione non hai compilato tutti i campi", preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
else {
RisorsaSelezionata?.SetDescrizione(Descrizione: textView.text)
RisorsaSelezionata?.SetRisorsaRapporto(RisorsaRapportino: RisorsaRapportino)
if(Stato == "Inserimento") {
RisorsaSelezionata?.InserisciRisorsa(completion: { result in
if(result == true) {
self.CaricaRisorseCantiere()
}
else {
let alertController = UIAlertController(title: "Errore", message: "Non sono riuscito ad inserire la risorsa!", preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
})
}
}
}
@objc func Return(sender: UIButton!) {
//self.performSegueToReturnBack()
let CantiereSelezionato = GestioneCantieriViewController(CantiereSet: self.Cantiere)
self.present(CantiereSelezionato, animated: true, completion: nil)
}
//Metodo delegato che ritorna il numero di righe
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return UserLoad.count
}
// Metodo delegato che ritorna il valore mostrato nella riga
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
RisorsaSelezionata?.SetIdUtente(IdUtente: UserLoad[row].IdUtente)
return UserLoad[row].Username
}
// Metodo Delato Chiamao quando viene selezionata unarigha
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print("\n UserLoad[row].IdUtente \(UserLoad[row].IdUtente!)")
RisorsaSelezionata?.SetIdUtente(IdUtente: UserLoad[row].IdUtente!)
print("\n ID Risorsa \(String(describing: RisorsaSelezionata?.GetIdUtente()))")
}
//Number of Columns into UIPickerView
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
//this func get select Date from UIDatePicker
@objc func datePickerValueChanged(_ sender: UIDatePicker) {
RisorsaSelezionata?.SetData(Data: Extensioni.CastFromDateToString_SqlServer_DateTime(mydate: sender.date))
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return RisorseUmaneLoad.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
RisoseUmaneTableView.beginUpdates()
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! CustomTableViewCellArticolo
cell.layer.cornerRadius = 10
cell.layer.borderWidth = 1.0
cell.layer.borderColor = UIColor.gray.cgColor
cell.layer.masksToBounds = true
cell.labCodArt.text = RisorseUmaneLoad[indexPath.row].Risorsa
cell.labDescrizione.text = RisorseUmaneLoad[indexPath.row].Descrizione
cell.labPrezzo.text = ""
RisoseUmaneTableView.endUpdates()
return cell
}
func CaricaRisorseCantiere() {
if(Stato == "Inserimento") {
let rtemp = RisorsaUmana(CantiereInterno: Cantiere)
rtemp.CaricaRisorseUmaneCantiere(completion: { result in
self.RisorseUmaneLoad.removeAll()
self.RisorseUmaneLoad = result
DispatchQueue.main.async {
self.RisoseUmaneTableView.reloadData()
}
});
}
}
......
Controller :
func CaricaUtenti(completion: @escaping ([UserStruct]) -> Void) {
DispatchQueue.global(qos: .userInteractive).async {
let rtemp = UserModel()
rtemp.CaricaRisorse(completion: { result in
completion(result)
})
}
}
型号:
func CaricaRisorse(completion: @escaping ([UserStruct]) -> ()) {
DispatchQueue.global(qos: .userInteractive).async {
let jsonrequest = JSON()
let jsonarray: [String: Any] = ["Default": "0"]
jsonrequest.GetArray(Tipo: "User", Router: "/RisorseUmane/CaricaRisorse", ValueArray: jsonarray, completion: { result in
completion(result as! [UserStruct])
})
}
}
func GetArray(Tipo: String, Router: String, ValueArray: [String: Any], completion: @escaping (_ ret: Codable) -> ()) {
let semaphore = DispatchSemaphore(value: 1)
semaphore.wait()
let db = Database()
let json: [String: Any] = ValueArray
let jsonData = try? JSONSerialization.data(withJSONObject: json)
var request = URLRequest(url: URL(string: db.GetServerURL() + Router)!)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Accept")
request.httpMethod = "POST"
request.httpBody = jsonData
URLSession.shared.dataTask(with: request) { (data, response, error) in
if error != nil {
print(error!.localizedDescription)
}
guard let data = data else { return }
do {
if(Tipo == "User") {
let value = try JSONDecoder().decode([UserStruct].self, from: data)
completion(value)
}
} catch let error {
print("Error JSON: ", error)
}
}.resume()
semaphore.signal()
}
最佳答案
您可以从 Xcode 菜单安装“Network Link Conditioner”:打开开发人员工具
> 更多开发人员工具
。该工具允许您在不同的网络条件下进行测试。
传递给URLSession.dataTask
的处理程序可能应该将有关成功或失败的信息传递回调用者。现在,如果数据为 nil
,则如果出现错误,它会简单地返回。考虑向处理程序添加除数据之外的额外值。例如,如果数据丢失而发生错误,则可以传递 _ success: Bool
为 false
。
... completion: @escaping (_ success: Bool, _ ret: Codable) -> ()
关于ios - UIPickerView 并不总是显示 3g 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52255390/
我目前正在尝试让 g++ 工作,并查看 http://gcc.gnu.org/install/build.html ,我似乎找不到它在哪里说如何“执行编译器的 3 阶段 bootstrap ”。我在哪
James Powell 在他对即将举行的演示文稿的简短描述中说,他自豪地发明了最粗糙的 Python 单行代码之一: (None for g in g if (yield from g) and F
请告诉我我的证明是否正确 We have a connected graph, and specific vertex u in V(G). Suppose we compute the dfs tr
下面的test2和test3结果是不同的。 我对此感到困惑,因为它看起来像相同的逻辑,并且与linux bash ||逻辑不同。 $data = @( [PSCustomObject]@{St
我试图找到一个明确的 G 代码语法规范,而不是单个 G 代码的含义,我无处不在的规范,我的意思是详细的语法规范,目的是编写解析器。 我编写解析器没有问题,我只是在寻找语法规范,例如。我知道您不必总是为
我写了这个 mixin,但它循环了很多时间。你能帮我优化我的代码吗?或者你能建议一些其他的东西来获得想要的结果吗? dfgdfgsdfgsdf 最佳答案 希望这就是您要找的。 $spaces: (4,
默认情况下,g++ 似乎会省略未使用的类内定义方法的代码。示例 from my previous question : struct Foo { void bar() {} void baz(
是否可以将文件内容通过管道传送到 g++编译程序? 我想这样做是因为我想使用数据库中的文件而不是磁盘上的物理文件。可以通过我制作的 API 轻松检索文件内容。 例如,我想做这样的事情: g++ con
如何profile c++代码获取每行代码的调用次数和消耗时间,就像profile工具一样在 Matlab 中呢? 我尝试使用-fprofile-arcs之类的东西,但它只生成代码覆盖率报告,其中可以
如何在几行代码上禁用所有警告。可以使用 GCC 诊断功能禁用特定警告,但是否有针对所有警告的标志。我尝试了这个方法,但不起作用 #pragma GCC diagnostic push #pragma
我有一个链接到 opencv 2.2 的可执行文件。但是,我删除了 opencv 2.2 并安装了 opencv 2.3。 问题是,有没有办法在不重新编译整个源代码的情况下将这个可执行文件链接到新的共
在编译带有一些标志的以下文件时,是否可以让 g++ 显示错误? #include using namespace std; int main() { int arr[ 2 ]; cout
在学习 Haskell 时,我遇到了一个挑战,要找到两个函数 f 和 g,例如 f g 和 f 。 g 是等价的(并且是总计,因此像 f = undefined 或 f = (.) f 这样的东西不算
根据我的理解,Theta 位于 Big O 和 Omega 之间,但我看到了这个声明,但我无法理解为什么交集会出现在这里。我能否对 Θ(g(n)) = O(g(n)) ∩ Ω(g(n)) 获得数学和分
我需要为这个递归函数编写一个迭代函数。 int funcRec(int n){ if(n>1) { return 2*funcRec(n - 1) + 3*funcRec(n
我在 github repository 上有代码示例并在 travis-ci 上创建了一个构建便于复制。 最小的、完整的和可验证的例子 可能不是最小的,但我相信它足够小 它使用 boost.inte
编辑:我们将调用箭头 p纯如果存在这样的函数f即:p = arr f . 我试图更好地掌握 Haskell 中的 Arrows,我想弄清楚什么时候 f >>> (g &&& h) = (f >>> g
我有两个(或更多)函数定义为: val functionM: String => Option[Int] = s => Some(s.length) val functionM2: Int => Op
好像是的。任何直观或严肃的证据都值得赞赏。 最佳答案 没有。 我认为您的问题等同于:给定函数 f 和 g,f 是 O(g) 或 g 是 O(f) 是否总是正确的?这在 SE Computer Scie
如果我设法证明 f(n) = o(g(n))(小 o),那么这两个函数的总和 f( n) + g(n) 应该被“更大”的函数 g(n) 紧紧束缚。 然而,我在证明这一点时遇到了一些麻烦。 最佳答案 以
我是一名优秀的程序员,十分优秀!