gpt4 book ai didi

ios - NavigationViewController 内的 TabViewController 内的 TableViewController 在运行时不显示导航标题和项目,但在 Storyboard 中显示

转载 作者:搜寻专家 更新时间:2023-11-01 07:32:07 25 4
gpt4 key购买 nike

我在带有导航标题和项目的 NavigationController 内的 TabViewController 内有一个 TableViewController,如下所示:
enter image description here

在运行时,导航栏在那里,但没有显示标题和添加项目,如下所示:(不要介意白色的空白,在我的设备中它工作,但在模拟器中没有 - 我在stackOverflow,但仍然没有解决方案)
enter image description here
另一个 TabBar 项目指向常规 UIView,它也不显示导航栏标题和栏项目。

我尝试添加另一个 UIView,它将成为 TabBarViewController 和 TableViewController 之间的中介,这解决了问题,但这让我失去了 TableViewController 中的 TabBar 功能。我试图从我的 TableViewController 指向导航栏,但无法从那里访问“viewDidAppear”或 navigationBar 类等方法,因为它充当 tableView 的 Controller 。

TableViewController 类

import UIKit
import Parse
import ParseUI

class MeetsTableViewController: PFQueryTableViewController {

// Initialise the PFQueryTable tableview
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
//self.tableView.contentInset = UIEdgeInsetsZero;
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

// Configure the PFQueryTableView
self.parseClassName = "Meets";
self.pullToRefreshEnabled = true;
self.textKey="city";
self.paginationEnabled = false;

}


// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {
let query = PFQuery(className: "Meets");
query.orderByDescending("numberOfComming");
return query;
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {

var cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as! CarTableViewCell!;

if cell == nil {
cell = CarTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "MyCell");
}
if let cityName = object?["city"] as? String{
cell?.meetName?.text = "מפגש ב\(cityName)";
}
if let address = object?["address"] as? String{
cell?.meetAddress?.text = address;
}
if let date = object?["date"] as? String{
cell?.meetDate?.text = date;
}
if let time = object?["time"] as? String{
cell?.meetTime?.text = time;
}
if let people = object?["numberOfComming"] as? Int{
cell?.peopleAttending?.text = "\(people)";
}

if let thumbnail = object?["meetImg"] as? PFFile {

thumbnail.getDataInBackgroundWithBlock{
(imageData, error) -> Void in
if error == nil {
let image = UIImage(data: imageData!)
cell.meetImage.image = image
}
}
}

return cell;
}

//delegate method
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
moveToDetail();
}

func moveToDetail(){
let meetDetail=storyboard?.instantiateViewControllerWithIdentifier("meet") as! MeetDetailViewController;

if let indexPath = self.tableView.indexPathForSelectedRow {
let row = Int(indexPath.row);
meetDetail.currentObject = (objects?[row] as? PFObject)
}
navigationController?.showViewController(meetDetail, sender: self);
}

}

TabViewController 类

import UIKit

class MeetingsTabViewControllerViewController: UITabBarController {

override func viewDidLoad() {

super.viewDidLoad()
// set red as selected background color
let numberOfItems = CGFloat(tabBar.items!.count)
let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
tabBar.selectionIndicatorImage = UIImage.imageWithColor(UIColor(hexString: "#8c332b")!, size: tabBarItemSize).resizableImageWithCapInsets(UIEdgeInsetsZero);
tabBar.backgroundImage = UIImage.imageWithColor(UIColor(hexString: "#c1463e")!, size: tabBarItemSize).resizableImageWithCapInsets(UIEdgeInsetsZero);
// item selected color
tabBar.tintColor = UIColor.whiteColor();
// remove default border
tabBar.frame.size.width = self.view.frame.width + 4;
tabBar.frame.origin.x = -2;

}
}

extension UIImage {

class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect: CGRect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(size, false, 0);
color.setFill();
UIRectFill(rect);
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}

}

NavigationViewController 类

import UIKit

class MeetsNavigationViewController: UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()

}



}

最佳答案

已解决
似乎无法从标签栏子项向导航栏添加项目,但可以向标签栏 Controller 添加项目,所以这就是我所做的。我只是根据我选择的标签更改标题,我将这个方法添加到标签栏 Controller :

override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if item.tag==0{
navigationItem.title="המפגשים שלי";
}else{
navigationItem.title="כל המפגשים";
}
}

关于ios - NavigationViewController 内的 TabViewController 内的 TableViewController 在运行时不显示导航标题和项目,但在 Storyboard 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31930958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com