在我的应用程序中,我正在尝试使用json数据发出http post请求.以下json必须转移到api
{
"Password":"123456",
"Email":"test@gmail.com"
}
Run Code Online (Sandbox Code Playgroud)
这是我执行此任务的代码
let dict = ["Email": "test@gmail.com", "Password":"123456"] as [String: Any]
if let jsonData = try? JSONSerialization.data(withJSONObject: dict, options: []) {
let url = NSURL(string: "http://xxxxxxxxx.net/api/Login")!
let request = NSMutableURLRequest(url: url as URL)
request.httpMethod = "POST"
request.httpBody = jsonData
let task = URLSession.shared.dataTask(with: request as URLRequest){ data,response,error in
if error != nil{
print(error?.localizedDescription)
return
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
if let parseJSON = json {
let resultValue:String …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有两个嵌入在导航控制器中的视图控制器(比如 viewControllerA 和 viewControllerB)。在RootViewController的,我不希望显示导航栏,所以在viewWillAppear和viewWillDisappear我已经添加THES线:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
Run Code Online (Sandbox Code Playgroud)
现在从 viewcontrollerB 在导航栏下键入后退按钮(当它开始消失时)出现黑色视图。如何删除那个黑色视图?
PS 我已经将导航栏设置isTranslucent为 false 但它并没有解决问题。在我的项目中,我没有使用故事板。
在我的应用程序中,我有表视图控制器.当用户在tableview的最后一行键入时,应显示操作表以要求注销.以下是此操作的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
//..
case 1:
//..
case 2:
//..
case 3:
let logOutMenu = UIAlertController(title: nil, message: "Are you sure want to logout?", preferredStyle: .actionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let logOutAction = UIAlertAction(title: "Log out", style: .default, handler: { (UIAlertAction) in
print("sign out")
})
logOutMenu.addAction(cancelAction)
logOutMenu.addAction(logOutAction)
self.present(logOutMenu, animated: true, completion: nil)
default: break
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但行动表有奇怪的行为.显示操作表大约需要10秒钟(甚至更长时间).我在真实设备上也注意到了同样的行为.我做错了什么?