我是离子框架的新手
登录应用程序后,我将重定向到实例页面。 在实例页面中,我启用了导航栏。 但我看到导航后退按钮已启用,刷新后,我回到了导航栏。
我尝试添加 1实例页面中的hide-nav-bar = false(不使用) 2 hide-back-button =真实页面中的true(不使用) 3在登录控制器中,我尝试添加 $ ionicHistory.nextViewOptions({ disableBack:true }); 在我之前 $ state.go( '实例'); (没用)
但是,当我刷新,从那时起,它工作正常。 有人可以帮忙吗
答案 0 :(得分:1)
您可以使用$ionicNavBarDelegate
在您的控制器中
import UIKit
class HomeViewController: UIViewController ,UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var collectionView1: UICollectionView!
var BTdata = [BTData]()
override func viewDidLoad()
{
super.viewDidLoad()
ListBusinessTypes()
}
// Values from Api for Business Types
func ListBusinessTypes()
{
let token = NSUserDefaults.standardUserDefaults().valueForKey("access_token") as! String
let headers = ["x-access-token": token]
let request = NSMutableURLRequest(URL: NSURL(string: “some url“)!,
cachePolicy: .UseProtocolCachePolicy,
timeoutInterval: 10.0)
request.HTTPMethod = "GET"
request.allHTTPHeaderFields = headers
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if (error != nil)
{
print(error)
let ErrorAlert = UIAlertController(title: "Error", message: "Problem with internet connectivity or server, please try after some time", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
ErrorAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(ErrorAlert, animated: true, completion: nil)
}
else
{
if let json = (try? NSJSONSerialization.JSONObjectWithData(data!, options: [])) as? Dictionary<String,AnyObject>
{
let success = json["success"] as? Int
if(success == 1)
{
if let typeValues = json["data"] as? [NSDictionary]
{
dispatch_async(dispatch_get_main_queue(),{
for item in typeValues
{
self.BTdata.append(BTData(json:item))
}
self.collectionView1!.reloadData()
})
}
}
else
{
let message = json["message"] as? String
print(message)
let ServerAlert = UIAlertController(title: "Error", message: message, preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
ServerAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(ServerAlert, animated: true, completion: nil)
}
}
}
})
dataTask.resume()
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return BTdata.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell: collview1 = collectionView.dequeueReusableCellWithReuseIdentifier("Cell1", forIndexPath: indexPath) as! collview1
cell.lblCellA.text = BTdata[indexPath.row].BTNames
cell.imgCellA.image = UIImage(named: tableImages[indexPath.row])
return cell
}
collection view cell space and size
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
return CGSizeMake((self.view.frame.size.width/4) - 10, (self.view.frame.size.width/4) - 15);
}
}