我有一个REST API,并且正在通过Json获取所有数据,然后将其放入IOS TableView中。我的问题是像NULLJson一样返回了一些数据
"vote_status":null
Run Code Online (Sandbox Code Playgroud)
我试图快速获取该NULL值并将其更改为字符串“ 0”,但是这样做很难。我到目前为止
if var vote_status = Stream["vote_status"] as? String {
if (vote_status == (vote_status)[NSNull]) {
vote_status = "0"
}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到这个编译错误:
无法使用索引类型为((NSNull).Type'(也称为'NSNull.Type')的索引对类型为'String'的值进行下标
我这样做是因为nil和null似乎不起作用,所以我不能这样做。
if (vote_status == nil) ...
Run Code Online (Sandbox Code Playgroud) 我正在youtube上学习一些快速的3个以下课程.我编写的代码用于创建用户帐户并在Firebase数据库中存储详细信息.在测试时,我可以直到提交注册表单.然后我收到以下错误:
[Generic] Creating an image format with an unknown type is an error.
Fatal Error: unexpectedly found nil whilst unwrapping an Optionional value.
Run Code Online (Sandbox Code Playgroud)
我在下面的代码块中突出显示了以下行:
exc_bad_instruction(code=exc_i386_invop subcode=0x0)
Run Code Online (Sandbox Code Playgroud)
以下是我的代码.我已经突出显示了抛出异常的位置.任何援助将不胜感激.
import UIKit
import Firebase
class Signup_ViewController: UIViewController,
UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// Input data fields for signup form
@IBOutlet weak var usernameField: UITextField!
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var nameField: UITextField!
// Password data field for signup form
@IBOutlet weak var passwordField: UITextField!
@IBOutlet weak var confirmPasswordField: UITextField!
// Next button for …Run Code Online (Sandbox Code Playgroud) 我在解雇VC时有一点问题。
我的项目有2个Viewcontroller。Viewcontroller A和ViewcontrollerB。
Viewcontroller A有一个按钮。如果我按此按钮,第二个ViewController B弹出。
第二个ViewController(B)有一个按钮。如果我单击此按钮,此操作将开始:
@IBAction func dismiss(_ sender: UIBarButtonItem) {
self.presentedViewController?.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
该操作实际上应该关闭Viewcontroller,并应再次向我显示ViewcontrollerA。
但是,如果我按下此按钮,则什么也不会发生。
我忘了什么吗?
几个小时我一直在搞乱这些限制,无法解决这个问题.我需要在文本视图中使用动态单元格高度.
正如你可以看到它重叠我的时间戳.截至目前,我对时间戳有零(无)限制.我已经尝试了所有可能的组合来完成这项工作,我无法得到它.
也在使用
override func viewDidLoad() {
super.viewDidLoad()
//TableView Cell word wrap (Dynamic Text)
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.estimatedRowHeight = 78
self.tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud) 我需要将此字符串值传递给另一个viewController.由于某种原因,我得到一个sigabrt错误.任何人都可以指出我做错了什么?
需要将userIdentityString值传递给userCellTapped viewcontroller
class GeneralChatroom: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate {
//Get Data of current cell that has been tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
//Eliminate highlight after cell is tapped
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let userIdentityString : String = generalRoomDataArr[indexPath.row].cellUserId
let destinationUID = userCellTapped()
destinationUID.programVar = userIdentityString
destinationUID.performSegue(withIdentifier: "profileTapped", sender: self)
}
}
import UIKit
class userCellTapped: UIViewController {
var programVar : String!
override func viewDidLoad() {
super.viewDidLoad()
print("testbles", programVar)
}
}
Run Code Online (Sandbox Code Playgroud) 我是编码和堆栈溢出的新手,我试图让用户在关闭应用程序后仍然保持登录状态.我也不希望他们总是在屏幕上看到登录.即使关闭应用程序并重新打开应用程序,我该如何保持用户登录.我正在使用Swift 3.0,Xcode 8和Firebase.
import UIKit
import Firebase
import SwiftKeychainWrapper
class LoginViewController: UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var pwField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginViewController.dismissKeyboard))
//Uncomment the line below if you want the tap not not interfere and cancel other interactions.
//tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
// Do any additional setup after loading the view.
}
func dismissKeyboard() {
//Causes the view (or one of its embedded text fields) to …Run Code Online (Sandbox Code Playgroud) 我试图在Xcode 8中将C#示例转换为swift,但我一直遇到语法问题.查看代码的小例子:
public class ToonAPIClient {
private var APIManagerBaseAddress: URL!
private var APIBaseAddress: URL!
public init() {
APIManagerBaseAddress = URL(String: "https://path.to.baseurl/")
APIBaseAddress = URL(String: APIManagerBaseAddress + "append/path/data/")
}
}
Run Code Online (Sandbox Code Playgroud)
APIManagerBaseAddress我收到错误
参数标签'(String :)'与任何可用的重载都不匹配
并为APIManagerBaseAddress
二进制运算符'+'不能应用于'URL'类型的操作数 和'字符串'
任何帮助都很受欢迎,因为我尝试了一些语法可能性:)
-edit-感谢大家的帮助和建议!
我有地图视图,用户可以拖动标记.标记点按时,会显示包含标记位置的代码段.
如何获得标记的经度和纬度?如果标记被拖动到另一个位置.
这就是我所做的:
var latitude = -7.034323799999999
var longitude = 110.42400399999997
var displayAddress = [String]()
func customizeMap() {
mapView.delegate = self
let camera = GMSCameraPosition.camera(withLatitude: Double(latitude), longitude: Double(longitude), zoom: 17)
mapView.animate(to: camera)
let markerImage = UIImage(named: "ic_home_detail_marker_location")
let markerView = UIImageView(image: markerImage)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(Double(latitude), Double(longitude))
marker.isDraggable = true
marker.iconView = markerView
marker.snippet = displayAddress[0]
mapView.selectedMarker = marker
marker.map = mapView
}
Run Code Online (Sandbox Code Playgroud)
现在我正在使用静态经度和纬度
我希望用户在应用程序中使用麦克风,并将相应的密钥添加到info.plist"Privacy-MicrophoneUsageDescription",如果用户点击麦克风按钮,则会出现带有使用权限问题的窗口.如果用户点击"允许",该应用程序工作正常,没有一些问题.但如果没有,再次按麦克风按钮,应用程序崩溃.
我想要的是,每次按下按钮时检查NSMicrophoneUsageDescription状态.如果被拒绝,请再次询问用户是否允许.
我知道如何在我的spriteKit游戏中实现一个商店,用户可以用他们在游戏中获得的硬币购买不同的玩家吗?那里有任何教程吗?
swift3 ×10
swift ×8
ios ×7
firebase ×2
xcode8 ×2
google-maps ×1
json ×1
microphone ×1
nsnull ×1
segue ×1
sprite-kit ×1
uitextview ×1