我已将Rest Api加载到不同的页面上,我已使用UIPageViewController进行了上下页面编辑,其中一个菜单页面具有“类别和子类别”,因此当我单击“类别”或“子类别”时我想这样做每当我尝试从Rest Api加载数据但无法加载其他数据时,都会从Rest Api加载不同的数据。我想加载不同的数据,在select方法中的click事件上没有问题,我的问题是数据无法更改为screenType,我在UiPageviewcontroller类中声明了Enum。
这是UIpageviewcontroller类(Swift 3)上的Enum代码:
enum ScreenType: String
{
case home
case appsAndSoftware
}
var screenType: ScreenType = .home
这是Rest Api的代码,用于显示不同的数据在Tableview上使用Restkit,TutorialViewController是我的UIPageviewController类
func GetJsonData()
{
let objectManager = RKObjectManager(baseURL: URL(string: "/wp-json/wp/"))!
let first = self.storyboard?.instantiateViewController(withIdentifier: "TutorialViewController") as! TutorialViewController
var id = "1419"
if first.screenType == .appsAndSoftware
{
id = "1412"
}
else if first.screenType == .appsAndSoftware2
{
id = "1489"
}
let path = "v2/posts/\(id)"
objectManager.addResponseDescriptor(RestKitHelper.getJsonData(path: path))
objectManager.getObjectsAtPath(path, parameters: nil, success: { operation, mappingResult in
let results: [News] = mappingResult?.array() as! [News]
if results.count > 0{
for receivedData in results{
self.data.append(receivedData)
}
}
DispatchQueue.main.async(execute: {
self.sectb.reloadData()
})
}, failure: { operation, error in
print("Fail")
})
}
这是我的菜单选择方法
switch sections[section].items[row - 1]
{
case "Apps & Software":
let destination = self.storyboard?.instantiateViewController(withIdentifier: "TutorialViewController") as! TutorialViewController
destination.screenType == .appsAndSoftware
self.navigationController?.pushViewController(destination, animated: true)
print("Apps And Software")
let newFrontController = UINavigationController.init(rootViewController: destination)
revealviewcontroller.pushFrontViewController(newFrontController, animated: true)
break
default:
break
}