It helps a bit, but this way I change the Table View Cell Background "forever" to black, I just want to change it for one second, when it is clicked.
Post
Replies
Boosts
Views
Activity
Unfortunately it still does not work. Maybe because I worked with the storyboard ? I linked the table view cell to another view, it works, but if I click on the the table view cell it gets light grey for just a moment before it shows the next page. Thanks to you it changes back to the original color when I go back.
tableView.reloadRows(at: indexesToRedraw, with: .fade)
was the line of code, which caused that. Should I try to get rid of the link in the storyboard and try it with code ?
let indexesToRedraw = [indexPath]
selectedIndex = indexPath
array[indexPath.row] = true
tableView.reloadRows(at: indexesToRedraw, with: .fade)
sleep(1)
array[indexPath.row] = false
tableView.reloadRows(at: indexesToRedraw, with: .fade)
performSegue(withIdentifier: "shownext", sender: indexesToRedraw)
}
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = array[indexPath.row]
if selectedIndex == indexPath {
if array[indexPath.row] {
cell.backgroundColor = UIColor.black
}
else{
cell.backgroundColor = UIColor.blue
}
cell.setSelected(true, animated: true)
}
I basically did what you proposed, but the cell still turns light grey when clicked, I think somewhere in my code I did a basic mistake, but I can not figure it out. Thanks a lot for helping me this far.
Hi, thank you for your answer!
I go from A2-> using TabBar clicking on B -> B1->B2-> usingTabBar clicking on A -> and now get to A2, but I always want my TabBar to go to A1/B1, your first solution might work, but "popToRootViewController" does not work, what do you mean by that ?
Xcode "says" this function does not exist. Where exactly did you place this function? In the TabBarController or in the ViewController from A1?
import UIKit
class MyTabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
let rootView = self.viewControllers
[self.selectedIndex] as! UINavigationController
rootView.popToRootView // here the editor says that it does not work/exist //
}
I made a class for the tab bar Controller and connected it to the storyboard.
And what do you mean with IB ?
Thank you! I just made a new line, where no one was requested. Now it works like it should
I want a to do a popover window and that works if I have no Navgation Controller, because the new View appears over the old one.
B1->B2
If I set the background color of B2 to Clear Color and put a Label with a blue background color on it. The program does what I want. The tricky part now is that I want to include this simple behavior to my project, which needs a NavController.
Sorry, I am not very good at explaining my problem. But your first answer works really good, after a few difficulties. Thank you, the solution was much simpler than I thought it could be
Thank you all ! With sudo gem install cocoapods it worked!
Yes table_entries ist the data source. I appending for each loaded data set the name, because I do not know how to get to the result(s) afterwards.
Okay thank you ! But how I reload the table ? Is there a function for it ?
Thanks for your answer!
I am running the app on the iOS Simulator, the saved date is gone. I saved new data and closed and reopened xcode and the saved data were still there. Maybe it was just because of the update?
@Claude31 I close the app sometimes in the simulator and sometimes in xcode.
func saveProcedures(){
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else{
return
}
let context = appDelegate.persistentContainer.viewContext
let entityname = "Fruits"
guard let newEnity = NSEntityDescription.entity(forEntityName: entityname, in: context) else {
return
}
let newProcedure = NSManagedObject(entity: newEnity, insertInto: context)
let size = "5-7cm"
let caption = "Orange"
newProcedure.setValue(size, forKey: "size")
newProcedure.setValue(caption, forKey: "caption")
do {
try context.save()
print("saved fruit")
} catch {
print(error)
}
}
func loadProcedure (){
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else{
return
}
let context = appDelegate.persistentContainer.viewContext
let entityName = "Fruits"
let request = NSFetchRequest<NSFetchRequestResult>(entityName: entityName)
do {
let results = try context.fetch(request)
for r in results{
if let result = r as? NSManagedObject{
guard let importance = result.value(forKey: "size") as? String else {
return
}
guard let protocol_caption = result.value(forKey: "caption") as? String else {
return
}
self.fruitsArray.append(caption)
print("loaded")
}
}
print ("done")
print (fruitsArray)
} catch {
print(error)
}
}
I call this function right before I perform the segue with code
// function with code for loading the data from core data
print("loaded " +	caption)
self.caption = caption
self.size = size as! String
self.text = text as! String
}
}
print ("fertig")
} catch {
print(error)
}
let vc = ThirdViewController()
vc.initializer(caption : caption, size : size, text : text)
// Segue wird ausgeführt
performSegue(withIdentifier: "shownext", sender: indexesToRedraw)
}
I call saveProcedures() in the view did load of the view where I want to add data.
The same with load Procedure(), if I dont want to add more data I make save Procedure a comment in the viewdidload().
Thank you for your advice, I will try it out!
Thank you now it works!