作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是 IOS 的新手,我在做一个小项目。在我的项目中,我必须从主 Controller 中的 Web 服务 (SOAP) 加载数据 -> 将数据放入 seacond Controller 。因此,也许数据加载在后台线程中,该方法将数据在加载方法之前运行。那么我该如何解决呢?这是我的代码:
class MainRevealController: SWRevealViewController {
var conectData:ConnectData = ConnectData()
var menuTitle:[String] = []
var menuIcon:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
self.conectData.DemoSVNew("", key: "", commandType: "Menu", version: "") { (stringData) in
print("Hello I'm Loading Data")
let dataArray = stringData.componentsSeparatedByString("|")
let decodedData = NSData(base64EncodedString: dataArray[2], options: NSDataBase64DecodingOptions(rawValue: 0))
let decodedString = NSString(data: decodedData!, encoding: NSUTF8StringEncoding)
let dataArr = decodedString!.componentsSeparatedByString("<row>")
for i in 0...dataArr.count-1 {
let menu = dataArr[i].componentsSeparatedByString("|")
self.menuTitle.append(menu[3])
self.menuIcon.append(menu[4])
}
print("LoadData :",self.menuIcon.count)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "sw_rear" {
let mSegue = segue.destinationViewController as! MenuController
mSegue.menuTitle = menuTitle
mSegue.menuIcon = menuIcon
print("icon :",self.menuIcon.count)
print("title :",self.menuIcon.count)
}
}
最佳答案
在 MainRevealController
中进行以下更改。
class MainRevealController: SWRevealViewController {
override func viewDidLoad() {
super.viewDidLoad()
// *** Removed your API call from here as before it returns result you are on `MenuController` ***
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "sw_rear" {
let mSegue = segue.destinationViewController as! MenuController
// *** No need to pass data here, as your data is loaded in `MenuController` itself ***
}
}
}
以及 MenuController
中的后续更改。
class MenuController {
var conectData:ConnectData = ConnectData()
var menuTitle:[String] = []
var menuIcon:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
// *** Call your API here for menu items and perform action on result ***
self.conectData.DemoSVNew("", key: "", commandType: "Menu", version: "") { (stringData) in
print("Hello I'm Loading Data")
let dataArray = stringData.componentsSeparatedByString("|")
let decodedData = NSData(base64EncodedString: dataArray[2], options: NSDataBase64DecodingOptions(rawValue: 0))
let decodedString = NSString(data: decodedData!, encoding: NSUTF8StringEncoding)
let dataArr = decodedString!.componentsSeparatedByString("<row>")
for i in 0...dataArr.count-1 {
let menu = dataArr[i].componentsSeparatedByString("|")
self.menuTitle.append(menu[3])
self.menuIcon.append(menu[4])
}
print("LoadData :",self.menuIcon.count)
// *** Do somethign with your API result ***
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我希望你现在清楚了。快乐编码:)
关于ios - 在 IOS 的 webservice 中加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36394330/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!