swift 第五课 定义model类 和 导航栏隐藏返回标题
1. 网络请求返回数据时候,把数据转化为model,但是有时候会返回空的字符串,所以加载了个长度的判断:
class Model : NSObject{ var details_url:String? var easy_time:String? }
class func creatModel(dictionary :Dictionary<String, Any>) -> Model{
let model = Model.init()
model.setValuesForKeys(dictionary)
return model
}
override func setValue(_ value: Any?, forUndefinedKey key: String) {
}
if (self.model?.details_url) != nil && (self.model?.details_url?.characters.count)! > 0 { self.urlString = self.model?.details_url; } else if ( self.model?.easy_url ) != nil && (self.model?.easy_url?.characters.count)! > 0 { self.urlString = self.model?.easy_url; } else{ NSLog("无效的 web url"); }
2.隐藏导航栏 返回的标题:
self.navigationItem.backBarButtonItem = UIBarButtonItem.init(title: "", style:.plain, target: nil, action: nil)