Can't set custom class for cell in table view controller - ios

I'm really going crazy: I can't simply set my custom class for a UITableViewCell and I really don't know why.
My project
In my Storyboard I have a table view controller set to use ManageListsTVC.swift.
I want use a custom cell with dynamic prototypes so I create a custom class ListTVCell:
import UIKit
class ListTVCell: UITableViewCell
{
override func awakeFromNib()
{
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
So, clean, build, go in IB, select my table view controller, select the cell and...
I can't see my custom class! Why? Really, I waste so much time already for this stupid problem and I don't know what's wrong.
What I already tried
empty cache in ~/Library/Developer/Xcode/DerivedData
restart Xcode
clean project
check if ListTVCell.swift appears in compiled sources
I'm using Xcode 6.3.1.

--> incredibly after a complete reboot of my Mac now everything works and I can set my custom class.
Really strange but I decide to reply to my post, maybe can be helpful for someone else.

Related

What to check when outlet detection is not working?

I'm not sure what I did wrong, but I tried to connect the outlet from my main storyboard to my new ViewControllerTableViewCell.swift that I just created.
I set the class to ViewControllerTableViewCell
It contains
import UIKit
internal class ViewControllerTableViewCell : UITableViewCell {
override internal func awakeFromNib()
override internal func setSelected(_ selected: Bool, animated: Bool)
}
Now, I open up my Main.storyboard and attempting to drag my image and label
I did't see the auto detect come up.
However, when I tried to drag those into my ViewController.swift, it works.
To make sure it is not XCode Caching issue. I also restart my XCode, and still face same issue.
I was hoping to see something like this
How do I check further to make this work again?
Good question. That's one of the disadvantages of using the interface building. But anyways, here's a solution:
Make sure that your custom tableView class, ViewControllerTableViewCell is assigned to your custom cell in your storyboard, like so:
Then, click on the automatic thing above, and see if you're viewing the cell class.
Try again now to have an outlet.
Also, CMD+B (building) helps the Xcode to correct some things.
You need to assign the custom tableCell class to the cell in IB
//
//

Swift error : signal SIGABRT how to solve it

I'm just a beginner in Swift coding. My idea is quite simple which is an app with two buttons. When clicked, a textfield will change its text.
In the Main.StoryBoard, I add a textfield and two buttons.
In ViewController.swift file. I write as this:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var textfield: UITextField!
#IBOutlet weak var button: UIButton!
#IBOutlet weak var button2: UIButton!
#IBAction func action1(_ sender: UIButton) {
textfield.text="you just clicked on button1"
}
#IBAction func action2(_ sender: UIButton) {
textfield.text="you just clicked on button2"
}
}
It is supposed to be all right. However, an error appears which shows:
thread1:signal SIGABRT
in file AppDelegate.swift line:
class AppDelegate: UIResponder, UIApplicationDelegate
What is wrong with my code?
You get a SIGABRT error whenever you have a disconnected outlet. Click on your view controller in the storyboard and go to connections in the side panel (the arrow symbol). See if you have an extra outlet there, a duplicate, or an extra one that's not connected. If it's not that then maybe you haven't connected your outlets to your code correctly.
Just remember that SIGABRT happens when you are trying to call an outlet (button, view, textfield, etc) that isn't there.
For me it wasn't an outlet. I solved the problem by going to the error And reading what it said. (Also Noob..)
This was the error:
And The solution was here:
Just scroll up in the output and the error will be revealed.
To solve the problem, first clean the project and then rebuild.
To clean the project, go to MenuBar: Product -> Clean
Then to rebuild the project, just click the Run button as usual.
A common reason for this type of error is that you might have changed the name of your IBOutlet or IBAction you can simply check this by going to source code.
Click on the main.storyboard and then select open as
and then select source code
source code will open
and then check whether there is the name of the iboutlet or ibaction that you have changed , if there is then select the part and delete it and then again create iboutlet or ibaction.
This should resolve your problem
In my case I wasn't getting error just the crash in the AppDelegate and I had to uncheck the next option: OS_ACTIVITY_MODE then I could get the real crash reason in my .xib file
Hope this can help you too :)
I had the same problem. I made a button in the storyboard and connected it to the ViewController, and then later on deleted the button. So the connection was still there, but the button was not, and so I got the same error as you.
To Fix:
Go to the connection inspector (the arrow in the top right corner, in your storyboard), and delete any unused connections.
If you run into this in Xcode 10 you will have to clean before build. Or, switch to the legacy build system. File -> Workspace Settings... -> Build System: Legacy Build System.
This is a very common error and can happen for multiple reasons. The most common is when an IBOUTLET/IBACTION connected to a view controller in the storyboard is deleted from the swift file but not from the storyboard. If this is not the case, use the log in the bottom toolbar to find out what the error is and diagnose it. You can use breakpoints and debugging to aid you in finding the error.
To find out how to fix the error please use this article that I found on Google: https://rayaans.com/fixing-the-notorious-sigabrt-error-in-xcode
In my case there was no log whatsoever.
My mistake was to push a view controller in a navigation stack that was already part of the navigation stack.
Sometimes it also happens when the function need to be executed in main thread only, so you can fix it by assigning it to the main thread as follows :-
DispatchQueue.main.async{
your code here
}
For me, This error was because i had a prepare segue step that wasn't applicable to the segue that was being done.
long story:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let gosetup = segue.destination as! Update
gosetup.wherefrom = updatestring
}
This was being done to all segue when it was only for one. So i create a boolean and placed the gosetup inside it.
In my case, I was using RxSwift for performing search.
I had extensively kept using a shared instance of a particular class inside the onNext method, which probably made it inaccessible (Mutex).
Make sure that such instances are handled carefully only when absolutely necessary.
In my case, I made use of a couple of variables beforehand to safely (and sequentially) store the return values of the shared instance's methods, and reused them inside onNext block.
I had the same problem. In my case I just overwrote the file
GoogleService-Info.plist
on that path:
Platform\ios\YOUR_APP_NAME\Resources\Resources
In my case the files were present without data.
If this crash occurs when accessing a view controller within a package you may have to remove the Class and Storyboard ID from the view controller within the package and then add them again, run the project and the view controller should be found

Swift - A strange UIView instant covering over the whole top most ViewController

I just updated my Xcode to 8.2.1 and migrated my swift codes from 2.2 to 3.0.
After that, I ran into a situation that my top-most view controller was covered by a view (for more detail, please click to see the screenshot of Xcode debug hierarchy view), which never appeared when swift 2.2 was used. The top most VC is a DrawerController from https://cocoapods.org/pods/DrawerController, and is updated to the last version.
Because every touch event was received by the strange view, my app can't
work normally.
Is there any potential reason to make the view there?
Or is there any way to find out where the view come from?
If more information is needed, please let me know.
Thank you in advance.
For lack of reputation, I can't comment.
Have you ever tried to delete this "strange view"? Or just move it on top the UIView that contains your drawer?
I resolved this problem.
In my original codes, I subclassed DrawerController (say, MyDrawerController) and assigned the property centerViewController (the main page shown to the user in DrawerController) in the overrided viewDidLoad() in MyDrawerController. As a result, I ran into the trouble as described in my question above.
What I do to resolve the problem is make a main queue and move the codes which assigning the property centerViewController to the block of the main queue. (Codes of "BEFORE" and "AFTER" like bellow.)
Then, the problem was solved.
Don't know why the "BEFORE" codes worked fine in Swift 2.2 but failed in Swift 3.3. Could anyone tell the difference?
Thanks for your helping.
BEFORE:
class MyDrawerController: DrawerController {
override func viewDidLoad() {
self.centerViewController = aViewControllerInstant
}
}
AFTER:
class MyDrawerController: DrawerController {
override func viewDidLoad() {
DispatchQueue.main.async {
self.centerViewController = aViewControllerInstant
}
}
}

Events from storyboard don't reach view controller

(Newbie question) after mucking around with renaming folders/modules, etc. I find that events are no longer triggered. Looking in the story board inspector, all events look to be wired properly.
But no events are triggered in the view controller.
How can this be debugged? Could it be something wrong with the module names, relative paths or anything like that.
Code snippets:
class ViewController: UIViewController, STBackgroundTaskDelegate, MeshViewDelegate, UIGestureRecognizerDelegate, AVCaptureVideoDataOutputSampleBufferDelegate {
viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
// ... more here...
}
Receiving method:
#IBAction func overlayTypeChangedWithSender(_ sender: AnyObject) {
NSLog("Overlay type changed")
showOverlay()
}
You may have forgotten to change the Custom Class in Storyboard or Xcode caches outdated data. Do the following:
Copy the NameOfViewController to the Custom Class field for your viewController in Storyboard.
Clean the project (Product -> Clean)
Clear Derived Data. Here is how.
Restart Xcode
Build & Run
Have you tried connecting another control in one of your problem classes? If you can do that, have a look at the connections inspector for the new control, and earlier ones in the same view - they SHOULD be connected to the same class (of course), but if they are not, you just need to remove the old connection and reconnect

How to reload website page via swift when you click on UItabButton for iPhone

I am working on a swift iPhone application that loads a website page on viewDidLoad() function but I am stumped and have not been able to figure this next part out.
Basically what I am trying to do:
The dashboard controller (tab format) connects to three different pages which the first time you click on the tab it loads the page correctly via the viewDidLoad()
However when I go to a different tab then click back I need it to reload except it doesn't run the viewDidLoad() function again to load it.
Is there a function I can access or call? I have looked through app documents but I have failed to find it.
Thanks so much for the help!
You can use below view life cycle delegate method:
As per my understanding reloading a Webpage is not a UI update, So if you will use viewWillAppear so it will call before viewDidAppear which helps you to request faster.
override func viewWillAppear(animated : Bool)
{
super.viewWillAppear(animated)
}
Sounds like you are looking for viewDidAppear, which likes like the following in Swift 3 ...
override func viewDidAppear(_ animated: Bool){
super.viewDidAppear(animated) //call superclass's implementation first
//do stuff here ie. reload()
}

Resources