我正在使用tabbarcontroller作为初始视图控制器。我注意到,当我更改选项卡(单击另一个选项卡)时,它保留的内存仍然保留,而新的视图内存将其添加到旧的内存中。
我试图通过将所有变量更改为lazy来减少它(每个选项卡中的内存),并且它分别适用于每个视图,现在我没有那么高,因为我不得不增加能量影响部分。但是视图问题仍然存在(在对视图进行一些导航之后,我会收到内存警告)。
应用也崩溃了,并给了我错误:
由于内存问题迅速终止
我有5个标签:
First with tableView
Second with collectionView and tableview
Third with a Camera
fourth with a tableView
And The last one 4 tableView
通过搜索,我了解到我必须对viewDidDisappear或Unload
做些什么。Tabbar ScreenShot:
从StoryBoard到自定义导航控件创建自定义UITabbarController
序列:
从故事到第一个UITabbarController
标签(自定义控件)的自定义导航顺序:
这是我的自定义UITabbar
控制器类:
import UIKit
var tabBarItemCount = Int()
class CustomTabBarControl: UITabBarController, UITabBarControllerDelegate
{
@IBOutlet weak var tabBarItems: UITabBar!
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarStyle = .lightContent
self.delegate = self
statusBarStyleCheck = true
if let items = self.tabBarItems.items {
for i in 0..<items.count {
items[i].tag = i
}
}
}
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if item.tag == 4{
boolTabProfile = true
UserStore.shared.userIdToViewProfile = UserStore.shared.userId
}
}
}
这是我的自定义UINavigation
控制器类:
import UIKit
let NavigationTitleFont = "Nunito-Light"
class CustomNavigationControl: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
let textAttributes = [NSAttributedString.Key.font: UIFont(name: "Nunito-Light", size: 16)!,NSAttributedString.Key.foregroundColor:#colorLiteral(red: 0.7007879615, green: 0.6955401301, blue: 0.7298486829, alpha: 1)] as [NSAttributedString.Key : Any]
navigationBar.titleTextAttributes = textAttributes
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.setNeedsStatusBarAppearanceUpdate()
}
//Set navigation bar
var isNavigationbarHidden: Bool {
get {
return self.isNavigationbarHidden
}
set {
isNavigationBarHidden = newValue
}
}
//Navigation BarColor
var barColor: UIColor {
get {
return navigationBar.barTintColor!
}
set {
navigationBar.barTintColor = newValue
}
}
//Navigation Title Color
var navigationTitleColor: UIColor {
get {
return #colorLiteral(red: 0.7007879615, green: 0.6955401301, blue: 0.7298486829, alpha: 1)
}
set {
navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Nunito-Light", size: 16)!,NSAttributedString.Key.foregroundColor:newValue] as [NSAttributedString.Key : Any]
}
}
//Hide backButton
var hidebackButton: Bool {
get {
return navigationItem.hidesBackButton
}
set {
navigationItem.hidesBackButton = newValue
}
}
//NavigationBarImage
var navigationBarImage: UIImage? {
get {
return nil
}
set {
self.navigationBar.setBackgroundImage(newValue, for: UIBarMetrics.default)
self.navigationBar.shadowImage = UIImage()
}
}
//Left Navigation image
var leftNavigationCustomItem: UIImage? {
get {
return nil
}
set {
self.navigationItem.hidesBackButton = true
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: newValue, style: .plain, target: self, action: #selector(self.leftNavigationItemAction(_:)))
}
}
@objc func leftNavigationItemAction(_ sender: UIBarButtonItem) -> Void {
_ = popOrDismissViewController(true)
}
}
所有5个选项卡都通过自定义导航类进行连接。
有人可以向我解释如何解决这个问题。
任何帮助将不胜感激。
谢谢。