Ios Apple Watch-2基于页面的导航显示更改页面上的HTTP数据
我尝试使用Swift 2创建一个基于页面的导航观看应用程序。 我的应用程序如下: 对于这两个接口,我都有名为InterfaceController和EconomyInterfaceController的唯一控制器 在每个控制器中,我使用controllerinit()函数中的函数读取一些JSON数据Ios Apple Watch-2基于页面的导航显示更改页面上的HTTP数据,ios,swift,watchkit,apple-watch,watchos,Ios,Swift,Watchkit,Apple Watch,Watchos,我尝试使用Swift 2创建一个基于页面的导航观看应用程序。 我的应用程序如下: 对于这两个接口,我都有名为InterfaceController和EconomyInterfaceController的唯一控制器 在每个控制器中,我使用controllerinit()函数中的函数读取一些JSON数据 func setFeed(url: String) { let session = NSURLSession(configuration: NSURLSessionConfiguratio
func setFeed(url: String) {
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let request = NSURLRequest(URL: NSURL(string: url)!)
let task: NSURLSessionDataTask = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
if let data = data {
do {
let _data: AnyObject? = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
if let items = _data!["data"] as? NSArray{
self.tableOutlet.setNumberOfRows(items.count, withRowType: "row")
for (index, item) in items.enumerate() {
if let title = self.JSONString(item["title"]) {
if let spot = self.JSONString((item["spot"])) {
let news = newsItem(title: title, spot: spot)
let row = self.tableOutlet!.rowControllerAtIndex(index) as? RowController
row!.rowLabel!.setText(news.title) }
}
}
}
} catch {
}
}
}
task.resume()
}
我知道这不是HTTP请求的最佳方式,因为所有请求都在主线程和应用程序启动时运行。这不是我的主要问题,但如果你有任何提议,我不能拒绝:)
我的主要问题是,我是否调用willActivate()方法中的setFeed()方法,并使用
row!.rowLabel!.setText(news.title)
row!.rowLabel!.setText(news.title)
我的应用程序可以工作,但这不是一个好的选择,因为每次页面更改时,它都会一次又一次地更新内容
如果我在init()方法中调用setFeed()方法并使用
row!.rowLabel!.setText(news.title)
row!.rowLabel!.setText(news.title)
仅显示应用程序的第一页,不显示其他页面。这里怎么了