import UIKit
class Categorycell: UITableViewCell {
#IBOutlet weak var categoryImage : UIImage!
#IBOutlet weak var categoryTitle : UILabel!
func updateViews(category: category) {
categoryImage.images = UIImage(named: category.imageName)
categoryTitle.text = category.title
}
}
Try to change #IBOutlet weak var categoryImage : UIImage!
to #IBOutlet weak var categoryImage : UIImageView!
Related
Is it possible to make a label as a variable? I have multiple labels:
#IBOutlet weak var FL1at0: UIButton!
#IBOutlet weak var FL1at3: UIButton!
#IBOutlet weak var FL1at6: UIButton!
#IBOutlet weak var FL1at9: UIButton!
#IBOutlet weak var FL1at12: UIButton!
#IBOutlet weak var FL1at15: UIButton!
#IBOutlet weak var FL1at18: UIButton!
#IBOutlet weak var FL1at21: UIButton!
Sample Function:
else
{
UserDefaults.standard.set(true, forKey: "RedFl1")
self.FL1at0.setTitleColor(UIColor.red, for: .normal); self.ProgressUpdate()
}
Is there a way to set the table in a way to work like this:
self.FL1at"\(TimeStamp)".setTitleColor(UIColor.red, for: .normal)//TimeStamp comes from function
Try this:
let dict: Dictionary<String, UIButton> = ["FL1at0": FL1at0, "FL1at3": FL1at3, ...]
let x = "FL1at\(TimeStamp)"
if let y = dict[x] as? UIButton {
y.setTitleColor(UIColor.red, for: .normal)
}
You can't.
But you can save buttons in a dictionary:
var dic: [String: UIButton] = ["FL1at0": FL1at0]
then you can use name to access it like:
dic["FL1at\(TimeStamp)"]?.setTitleColorxxxx..
Here is the cell I want to reuse.
And there is a related cell class.
class FlightTransitTBCell: UITableViewCell {
#IBOutlet weak var abovebullet: UILabel!
#IBOutlet weak var bottomBullet: UILabel!
#IBOutlet weak var upBullet: UILabel!
#IBOutlet weak var downBullet: UILabel!
#IBOutlet weak var lblAboveTime: UILabel!
#IBOutlet weak var lblButtomTime: UILabel!
#IBOutlet weak var lblUpTime: UILabel!
#IBOutlet weak var lblDownTime: UILabel!
#IBOutlet weak var lblAboveAirPort: UILabel!
#IBOutlet weak var lblButtomAirPort: UILabel!
#IBOutlet weak var lblDownAirPort: UILabel!
#IBOutlet weak var lblUpAirPort: UILabel!
#IBOutlet weak var viaDown: UILabel!
#IBOutlet weak var viaUp: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
downBullet.text = "\u{2022}"
upBullet.text = "\u{2022}"
abovebullet.text = "\u{2022}"
bottomBullet.text = "\u{2022}"
downBullet.font = UIFont(name: getAppFont(), size: 20)
upBullet.font = UIFont(name: getAppFont(), size: 20)
abovebullet.font = UIFont(name: getAppFont(), size: 40)
bottomBullet.font = UIFont(name: getAppFont(), size: 40)
}
}
Following is my xib, which contain a tableview that I'm trying to display above cell.
And I register the cell from the xib class like this.
tableView.register(FlightTransitTBCell.self, forCellReuseIdentifier: "TransitCell")
then dequeue from tableview like this..
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let transitCell = tableView.dequeueReusableCell(withIdentifier: "TransitCell") as? FlightTransitTBCell{
transitCell.awakeFromNib()
transitCell.selectionStyle = .none
transitCell.setTransitView(indexPath.row, firstRoute, lastRoute)
transitCell.setBullet(outward_[indexPath.row])
if indexPath.row == 2 {
transitCell.backgroundColor = UIColor.green
}
return transitCell
}
return UITableViewCell()
}
I got the cell and it means my registration is working. But all my outlets are being nil and giving me error. I don't know what I'm doing is proper way of not. I'm not sure. This is my first time of doing like that and stuck here.
I'm adding a new TableVIewto the project and I'm also creating a custom class fro the cell. I'm doing as usual : New file/ Cocoa Touch Class / UITableViewCell / name. As soon as I start adding properties I get the error dough properties are declared as!. It doesn't happen on my other custom cell class. Can you see what am I doing wrong with this new class?
No error on this class :
import UIKit
class CalendarTableViewCell: UITableViewCell {
#IBOutlet weak var dayLabel: UILabel!
var cellId: String!
var cellWeekday: Int!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func prepareForReuse() {
super.prepareForReuse()
// Set your default background color, title color etc
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
and the new class that makes xCode complain:
import UIKit
class ProductTableViewCell: UITableViewCell {
#IBOutlet weak var productImageView: UIImageView!
#IBOutlet weak var productIDLabel: UILabel!
#IBOutlet weak var productIDInfoLabel: UILabel!
#IBOutlet weak var categoryLabel: UILabel!
#IBOutlet weak var categoryInfoLabel: UILabel!
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var nameInfoLabel: UILabel!
#IBOutlet weak var priceLabel: UILabel!
#IBOutlet weak var priceInfoLabel: UILabel!
#IBOutlet weak var quantityLabel: UILabel!
#IBOutlet weak var quantityInfoLabel: UILabel!
var productImage: UIImage!
var category: String!
var productId: String!
var name: String!
var price: String
var vendor: String!
var cellId: Int64
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
}
}
It's something I overlooked for sure but I can't spot it.
What should I check?
Your var cellId: Int64 is not initialized. In first cell you explicitly specified that you will initialize it before use with exclamation mark, but not in the second cell.
I have created the following view controller and wired up the controls in my storyboard to it.
import Foundation
import CoreData
import AppKit
protocol SubmissionViewControllerDelegate {
func controller(_controller: SubmissionViewController,
didAddSubmissionWithID profileID: Int64)
}
class SubmissionViewController : ViewController {
#IBOutlet var profileIDComboBox: NSPopUpButton!
var profileSelectedValue: String!
#IBOutlet var transcriptTypeComboBox: NSPopUpButton!
var transcriptTypeSelectValue: String!
#IBOutlet var submissionTypeComboBox: NSPopUpButton!
var submissionTypeSelectValue: String!
#IBOutlet var transcriptionTurnaroundComboBox: NSPopUpButton!
var turnaroundSelectValue: String!
#IBOutlet var persistentNoteComboBox: NSPopUpButton!
var persistentNoteSelectValue: String!
#IBOutlet var notesTextField: NSTextField!
#IBOutlet var batchIdentifierTextField: NSTextField!
#IBOutlet var languageInAudioComboBox: NSPopUpButton!
var languageSelectValue: String!
#IBOutlet var addResultViewButton: NSButton!
#IBOutlet var submissionFiles: NSTableView!
var delegate: SubmissionViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func save(_ sender: Any) {
guard case profileIDComboBox.titleOfSelectedItem =
profileSelectedValue else { return }
guard case transcriptTypeComboBox.titleOfSelectedItem =
transcriptTypeSelectValue else { return }
guard let delegate = delegate else { return }
delegate.controller(self, didAddSubmissionWithID:
profileSelectedValue)
}
}
I now want to store the titleOfSelectedItem from each NSPopUpButton in my Core Data Submission model. However, when I set the variables to be strings, I receive the error as follows:
Cannot convert value of type 'String?' to expected argument type '_OptionalNilComparisonType'
How do I accomplish this task?
I have custom UIView class where is have defined all my outlets, I need to change the texts from the information in dictionaries. Unable to do so help please.
/* THIS IS THE UIVIEW CLASS WHERE I WANT TO CHANGE THE TEXTS OF THE UILABEL. */
import UIKit
var alertAnimator : ReferAnimatorAlert = ReferAnimatorAlert()
class ReferAnimatorAlert : UIView
{
var detailArray : Array<NSMutableDictionary>!
#IBOutlet var alertView : UIView!
#IBOutlet var cellView1 : UIView!
#IBOutlet var cellView2 : UIView!
#IBOutlet var itemImage1 : UIImageView!
#IBOutlet var itemImage2 : UIImageView!
#IBOutlet var profileImage1 : UIImageView!
#IBOutlet var profileImage2 : UIImageView!
#IBOutlet weak var usernameLabel1 : UILabel!
#IBOutlet weak var usernameLabel2 : UILabel!
#IBOutlet var descriptionLabel1 : UILabel!
#IBOutlet var descriptionLabel2 : UILabel!
#IBOutlet var separatorView1 : UIView!
#IBOutlet var separatorView2 : UIView!
#IBOutlet var dismissOutlet : UIButton!
//MARK : - IBActions Declaration
#IBAction func dismissAction(sender : UIButton)
{
}
func setDetails()
{
for aDictionary in detailArray
{
if aDictionary["isHas"] as! Bool == true
{
usernameLabel2.text = aDictionary["Name"] as? String
descriptionLabel2.text = aDictionary["description"] as? String
}
else
{
//usernameLabel1.text = aDictionary["Name"] as? String
self.usernameLabel1.text = "This is a test."
//descriptionLabel1.text = aDictionary["description"] as? String
}
}
Animator.animateAlertCells(cellView1, cellView2: cellView2, alertView: alertView, dismissOutlet: dismissOutlet)
}
//THIS IS HOW I'M PASSING THE DATA FROM ANOTHER VIEWCONTROLLER.
var predicate : NSPredicate = NSPredicate(format: "isHighlighted == %#", true)
var resultDictionary = responseArray.filter(){predicate.evaluateWithObject($0)}
println(resultDictionary)
alertAnimator.detailArray = resultDictionary
overlayView.hidden = false
alertAnimator.setDetails()
The program breaks at ' usernameX.text = "Blah Blah" '