Can't connect TableView #IBOutlet to ViewController in Swift 2 - ios

I am building an app in which I want to press an annotation button and a TableViewCell will pop up. The problem is, when I try to create an #IBOutlet with control+ drag, to ViewController, it doesn't work. Also if I simply write the code : #IBOutlet weak var tableView: UITableView! on ViewController, when I run the app and hit the button, it crashes. What should I do?
Thanks in advance!

Chris,refer this image.Maybe it helps.

Make sure the given class in the Identity Inspector matches your class name.

Related

Swift. Can't Connect my Button to GIDSignIn Button in my Class

I am new to the swift. I follow the google tutorial to use Firebase Google OAuth method.
https://firebase.google.com/docs/auth/ios/google-signin
At step 9, I try to connect a custom button by control + drag to my property :
#IBOutlet weak var signInButton: GIDSignInButton!
But Xcode doesn't select it. It shows a pop up to create a new property. Though I have two others button: UIButton and when I try to connect to them, it works.
Could help me with that? It might miss some elements of my problem, so don't hesitate to ask.
Thank you!
Drag from the empty circle on the left of #IBOutlet to your button (not vice versa)

Indexing issues with Xcode 8

For some reason, defined outlets in XCode are not appearing in the right-click menu when I try to associate an object in the view with the outlet. For example:
import UIKit
class EditProfileTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
#IBOutlet var photoImageView: UIImageView!
#IBOutlet var businessName: UITextField!
#IBOutlet var businessAddress: UITextField!
#IBOutlet var businessHours: UITextField!
#IBOutlet var businessPhoneNumber: UITextField!
#IBOutlet var businessWebsite: UITextField!
...
As seen in the above example, there are many text fields that were defined, but if I try to associate the outlets to the objects in the view, it doesn't even appear in the right click menu here. (The photoImageView outlet was defined about a month ago, but for some reason the new outlets aren't working.)
In fact, the Identity Inspector shows nothing in the Class dropdown menu:
I believe there was some type of hiccup syncing files on Dropbox and something was accidentally deleted, and now I'm not quite sure how to fix this. I've tried:
Cleaning and re-building the project
Removing the project directories from "~/Library/Developer/Xcode/DerivedData" to force Xcode to re-index (and restarted Xcode)
and still nothing. I'd really hate to completely wipe my project and start from scratch, so I'm hoping to be able to get this resolved. I doubt it's anything as far as in the application that's done incorrectly since this worked before, but I'm not 100%.
If I copy my project folder to another location (let's say from DropBox to my Desktop), everything works perfectly fine! Confusing!
Any suggestions would be greatly appreciated.
There are two possible situation out of my head.
Double check that your view controller on storyboard is really connected to your code. Set a break point in viewDidLoad function to validate this.
If the connection is correct, then the cause of this issue could be that your outlet code is somehow disconnected from the elements on your storyboard. To fix this, do right click on your view controller like your second screen shot. In Outlets section, delete all connections by clicking on the little cross sigh in the middle. Then reconnect by ctr drag the element to your outlets in view controllers.

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

Container View - No Outlet Possible

I have a ViewController with a ScrollView in it, which has 2 ContainerViews in it. Now, every ContainerView loads a ViewController.
And in this ViewControllers (SubController from the ContainerViews) its impossible to do Outlets.
I get the little circles at the outlets, so the reference exists, but setting the text of a label for example, always results in the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
I've done the connection 10 times, with all possible names. Restarted xcode multiple times, still not working.
This answer could help: https://stackoverflow.com/a/28479934/2414069
EDIT: (below code is pseudo, everything is in the place it should..)
#IBOutlet weak var pinInfo_name: UILabel!
#IBOutlet weak var pinInfo_address: UITextView!
#IBOutlet weak var pinInfo_comment: UITextView!
self.pinInfo_name.text = defaults.stringForKey("activePin_name")!
self.pinInfo_address.text = defaults.stringForKey("activePin_address")!
self.pinInfo_comment.text = defaults.stringForKey("activePin_comment")!
SOULUTION:
Ok I slept about it, and found my error within 10 minutes: I wanted to change the .text properties from a object I created in another ViewController. I still have no Idea how to do that, buts thats a story for another time.
tl dr
Access right
As the link in your question points out, having multiple view controllers in your storyboard with the same class could cause this. Did you check that:
The child view controllers do not have the same class as each other
The child view controllers do not have the same class as the parent view controller
I made a test project and the I could connect the outlets of the UILabels in the child view controller to their respective UIViewController subclasses without any problem.
Here's my example:

Unable to access custom tableviewcell button properties in Swift

Working on my first iOS app. I have created nib and a custom tableview cell. The cell has buttons and labels. I am able to access the labels but for some reason I cannot get the properties of the buttons such as set title, for example. I only have access to the following:
cell.followUserButton(sender: AnyObject)
Why can't I just go
cell.followUserButton.setTitle = "Unfollow"
I looked online quite a bit. Couldn't find anything. Any help is appreciated. Thanks.
You have to write setTitle() this way:
cell.followUserButton.setTitle("Sample Title", forState: .Normal)
Btw setTitle() is function not a property.
Solved my own problem. I was setting it as only an IBAction. If you want to change the attributes then you also have to make the button an outlet too!
#IBOutlet weak var followUser: UIButton!
As you may already know, you can do this within the storyboard. Works perfectly now.

Resources