Swift UITableViewCell IBOutlets not displaying in StoryBoard - ios

I'm trying to follow this tutorial and add this to my app. However there were some problems so I tried recreating the project exactly from scratch in Xcode. The same problems keep coming up.
Firstly in the SidePanelViewController in the TableViewCell class that declare the IBOutlets
class AnimalCell: UITabelViewCell {
#IBOutlet weak var animalImageView: UIImageView!
#IBOutlet weak var imageNameLabel: UILabel!
#IBOutlet weak var imageCreatorLabel: UILabel!
func configureForAnimal(animal: Animal) {
animalImageView.image = animal.image
imageNameLabel.text = animal.title
imageCreatorLabel.text = animal.creator
}
}
do not show up in storyboard, so when I click on AnimalCell these IBOutlets should be there for me to connect in my TableView located in my Left and Right View Controllers, but nothing shows. The only IBOutlets that will work or allow me to create connection in StoryBoard is if the object is the actual view controller.
I tried using the assistant editor control dragged the UI elements and connect them regardless and eventually the dot in the circle shows its connected even though it still remains blank displaying in my Storyboard Outlets connections list, (but if I closedown and reopen xcode i have to do this again). If I compare this to both final project and the starter project downloaded from the website this is not correct. In the starter project from the website the IBActions and IBOutlets were pre-connected so they display in storyboard fine its just if I try to do this from scratch, I can't understand, why don't they display in Xcode in my Outlet connections list? (Even when I cut and paste the code from SidePanelViewController from the downloaded version from the website directly into mine still doesn't work).
Secondly when I actually run the project on the simulator it throws 2 errors in My App Delegate file and in my SidePanelViewController and it seems to highlight
let cell = tableView.dequeueReusableCellWithIdentifier(TableView.CellIdentifiers.AnimalCell, forIndexPath: indexPath) as AnimalCell
the full function is
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
tableView.dequeueReusableCellWithIdentifier(TableView.CellIdentifiers.AnimalCell, forIndexPath: indexPath) as AnimalCell
cell.configureForAnimal(animals[indexPath.row])
return cell
}
and in the App Delegate I get the same Thread 1: Exc_BreakPoint (code=Exc_I386_BPT, sub code = 0x0) and this on the line
class AppDelegate: UIResponder, UIApplicationDelegate {
Also the error I think might also be in
SidePanelViewController #objc
protocol SidePanelViewControllerDelegate {
func animalSelected(animal: Animal)
}
The final version downloaded from the website runs in the simulator perfectly fine, no errors. But its all the same code so I'm confused as to why the version I recreate is not working. Also when I complete the code using the downloaded starter project the left panel slides but the puppies button is acting as the left button as well, so its not sliding to the right, but no errors on running in the simulator come up though compared to the one I recreated from scratch.
I've deleted the contents in the derived data, deleted Xcode, installed as fresh even reverted back to 6.1 as 6.1.1 sourcekit was crashing more frequently than 6.1.
I'm very confused as to whats going on and why the original code set out in the tutorial does not work when I do it, but the downloaded final version works. I can't figure out what I'm doing wrong. I am new to Xcode and Swift. Can anyone help?

You've probably forgot to set AnimalCell as the class for the cell in the storyboard.
You'll need to select the cell and in the Utilities Sidebar, go to the Identity Inspector and fill in the Class field with AnimalCell.
Command + Option + 3 will take you directly to the correct screen.

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
//
//

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

Xcode 7.3 can't create xib with for UIView / UITableViewCell together

After I have updated to Xcode to 7.3, I found Xcode can't create Xib file, when I create UIView class or UITableViewCell. Does anybody know the reason?
Very traditional way and existing with any XCode version.
Right click on left panel
Select new file
Select iOS
Select User Interface
Select Empty then next
Give file name.
That will create empty xib, now drag and drop UITableViewCell and give class name as you have given in .h and .m file or swift file name.
Swift class with UITableViewCell
import UIKit
class CustomCell: UITableViewCell {
#IBOutlet weak var lblName : UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
Yeah, this is a surprising issue.
First create a nib (e.g. ProfileHeaderView.xib) file from File -> New file.
Then create a .swift (e.g. ProfileHeaderView.swift) file and subclass it from UIView.
Last (but not the least of course), go to Identity Inspector of your .xib file and change the name of class to the name of the created .swift file (e.g. ProfileHeaderView.swift).
Hope that helps.
Make sure that you select Cocoa Touch Class in iOS section, rather than OSX's Cocoa Class. That lets you check option Also create XIB File. This works perfectly in Xcode 7.3 for ViewControllers, and any UIView subclasses (e. g. UITableViewCell, UICollectionViewCell)
EDIT: but not for UIView

Connecting IBOutlet in Newly Created .Swift File

I wrote some code in Swift for an iOS app in XCode (7.1.1) and I can't use the drag and drop in the interface builder for the outlet I want to connect. I tried to do it manually too but the outlet didn't show up in the reference collection when I tried to do it.
I did see this answer:
Can't connect IBOutlet in Interface Builder
But this appears to be for Objective-C/older versions of XCode. The way I have it right now is I have my main DataViewController.swift file and then I created a PhotoViewer.swift file (it's just an example so the code doesn't really matter it's pretty simple). I used the following code:
import Foundation
import UIKit
class PhotoViewer: UIViewController {
#IBOutlet weak var viewerButton: UIButton!
func loadPhotoUI() {
viewerButton.setTitle("View Photos", forState: .Normal)
}
}
The viewerButton does not show up as an option and when I open up the story board and try to Ctrl-Click and drag to the file on the right side, it doesn't let me drop it in.
If I try it on the DataViewController.swift file (the one that was there when I started the initial template), it still works.
I'm guessing I just need to change a setting on the new file but I can't seem to figure that out. I basically will be using the classes functions in the DataViewController like:
let photoClass = PhotoViewer()
self.photoClass.loadPhotoUI()
etc etc. I'm just wanting to keep everything super organized.
I'm obviously a bit of a noob at Swift so thanks for the help!
Your ViewController in your Storyboard needs to be linked to your Swift file.
You have to change the Class to "PhotoViewer" in your Identify Inspector in your Storyboard Viewcontroller:

Resources