我的选项卡栏和导航栏就会消失。我已设法传递相关数据以便读取已选择的单元格,因此我可以将.txt文件插入到最终ViewController的UITextField中。它有点像动态textView。我仍然希望能够在文章视图(最终vc)中选择不同的选项卡。有没有办法在segue之后将NavBar和Tabbed View Bar保留在最终的viewController中,或者是否有办法通过Nav Controller传递数据。或者,抱歉这将是最后一个,我是否使用准备segue并推送以前的NavController(不太确定如何做到这一点)。抱歉,我无法发布超过2个图像链接,因此代码量很大。谢谢
这是来自rBVC.class(我的路障类别类文件),我有一个TableView:
class rBVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var rBTableView: UITableView!
var rBLabels = ["General Info", "Drunk Driving", "Arrest", "Searches"]
var rBIcons = [UIImage(named: "generalInfo"), UIImage(named: "drunkDriving"), UIImage(named: "arrests"), UIImage(named: "searches")]
var valueToPass: String!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return rBIcons.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let rBCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "rBCell", for: indexPath) as! rBCell
rBCell.textLabel!.text = self.rBLabels[indexPath.row]
rBCell.imageView!.image = self.rBIcons[indexPath.row]
return rBCell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You selected cell #\(indexPath.row)!")
//performSegue(withIdentifier: "rBASegue", sender: self)
print(valueToPass)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "rBSegue"){
/*let vcName = "rBTXT"
let vC = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(vC!, animated: true)*/
let indexPath = self.rBTableView.indexPathForSelectedRow!
let currentCell = self.rBTableView.cellForRow(at: indexPath) as! rBCell
valueToPass = currentCell.textLabel?.text
self.rBTableView.deselectRow(at: indexPath, animated: true)
// initialize new view controller and cast it as your view controller
let viewController = segue.destination as! rBAV
// your new view controller should have property that will store passed value
viewController.passedValue = valueToPass
print("\(valueToPass)test")
}
}
}
图片4:This is where I have the problem of the disappearing bar's.
class rBAV: UIViewController {
@IBOutlet var rBTV: UITextView!
var passedValue: String?
var rBArticle: String = ""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if passedValue == "General Info"{
rBArticle = "rBGI"
}
if passedValue == "Drunk Driving"{
rBArticle = "rBDD"
}
if passedValue == "Arrest"{
rBArticle = "rBA"
}
if passedValue == "Searches"{
rBArticle = "rBS"
}
// Save data to file
let fileName = "Test"
let DocumentDirURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let fileURL = DocumentDirURL.appendingPathComponent(fileName).appendingPathExtension("txt")
//print("FilePath: \(fileURL.path)")
/*** Read from project txt file ***/
// File location
let fileURLProject = Bundle.main.path(forResource: rBArticle, ofType: "txt")
// Read from the file
var readStringProject = ""
do {
readStringProject = try String(contentsOfFile: fileURLProject!, encoding: String.Encoding.utf8)
} catch let error as NSError {
print("Failed reading from URL: \(fileURL), Error: " + error.localizedDescription)
}
rBTV.insertText(readStringProject)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}