gpt4 book ai didi

ios - 无法弄清楚为什么我得到 "Class has no initializers"

转载 作者:行者123 更新时间:2023-11-28 21:26:17 24 4
gpt4 key购买 nike

我正在使用 Xcode 7.3.1 开发 swift2.2,我有一个类,其中出现“类没有初始化器”的错误。经过这么多谷歌搜索,我无法弄清楚为什么会这样?

我在我的 View Controller 中使用了 tableview,在 tableview 中添加了一个搜索栏,除此之外,我正在使用所有这些普通类和 tableview 扩展。

任何帮助将不胜感激。

谢谢

import UIKit
import Foundation
import RealmSwift


class ownersListView: UIViewController
{
//MARK:- Properties

var arSelectedRows:NSMutableArray?
var arSelectedRowValues:NSMutableArray?
var ownerIDList:NSMutableArray?
var userNameArray:NSMutableArray?
var companyOwnerList:NSMutableArray?

var ownerPicklistObject:OwnerPicklist?
var searchResults:Results<OwnerPicklist>?
var owner:Results<OwnerPicklist>?

var searchBarActive:Bool

@IBOutlet var tableView: UITableView!

override func viewDidLoad()
{
arSelectedRows = NSMutableArray()
userNameArray = NSMutableArray()
companyOwnerList = NSMutableArray()
ownerIDList = NSMutableArray()

ownerPicklistObject = OwnerPicklist()

owner = try! Realm().objects(OwnerPicklist).sorted("ownerPicklistFirstname")

tableView.reloadData()

if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
if ((NSUserDefaults.standardUserDefaults().objectForKey("addcontactOwnerList")) != nil)
{
arSelectedRows = NSUserDefaults.standardUserDefaults().objectForKey("addcontactOwnerList") as? NSMutableArray
}
}

tableView.tableFooterView = UIView()

reloadTableData()
}


//MARK:- Custom methods

func reloadTableData() -> Void
{
companyOwnerList?.removeAllObjects()

for i in 0..<owner!.count
{
ownerPicklistObject = owner![i]

if i == 0 && (ownerPicklistObject?.ownerPicklistFirstname != nil)
{
companyOwnerList?.addObject(NSString(format: "%@ %@", (ownerPicklistObject?.ownerPicklistFirstname)!, (ownerPicklistObject?.ownerPicklistLastname)!))
}
else if i > 0 && !(companyOwnerList?.containsObject((ownerPicklistObject?.ownerPicklistFirstname)!))!
{
companyOwnerList?.addObject(NSString(format: "%@ %@", (ownerPicklistObject?.ownerPicklistFirstname)!, (ownerPicklistObject?.ownerPicklistLastname)!))
}

ownerIDList?.addObject((ownerPicklistObject?.ownerPicklistID)!)
}

tableView.reloadData()
}

}


extension ownersListView:UITableViewDataSource, UITableViewDelegate
{

func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
if searchBarActive
{
if searchResults?.count == 0
{
let messageLabel = UILabel(frame: CGRectMake(UIScreen.mainScreen().bounds.origin.x, UIScreen.mainScreen().bounds.size.height / 2.5, UIScreen.mainScreen().bounds.size.width, 50.0))
messageLabel.text = "No Owner Found."
messageLabel.textColor = UIColor.blackColor()
messageLabel.textAlignment = NSTextAlignment.Center
messageLabel.font = UIFont.init(name: "Avenir-Medium", size: 16)
messageLabel.numberOfLines = 4

let msgView:UIView = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))

msgView.addSubview(messageLabel)

tableView.backgroundView = msgView
}
else
{
tableView.backgroundView = nil
}

return searchResults!.count
}
else if owner?.count >= 1
{
tableView.backgroundView = nil
return (owner?.count)!
}
else
{
if owner?.count == 0
{
let messageLabel = UILabel(frame: CGRectMake(UIScreen.mainScreen().bounds.origin.x, UIScreen.mainScreen().bounds.size.height / 2.5, UIScreen.mainScreen().bounds.size.width, 50.0))
messageLabel.text = "No Data Available."
messageLabel.textColor = UIColor.blackColor()
messageLabel.textAlignment = NSTextAlignment.Center
messageLabel.font = UIFont.init(name: "Avenir-Medium", size: 16)
messageLabel.numberOfLines = 4

let msgView:UIView = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))

msgView.addSubview(messageLabel)

tableView.backgroundView = msgView
}

return 0
}

}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)

if searchBarActive
{
ownerPicklistObject = searchResults![indexPath.row]
}
else
{
ownerPicklistObject = owner![indexPath.row]
}

var ownerName:NSString

if ownerPicklistObject?.ownerPicklistLastname != nil
{
ownerName = NSString (format: "%@ %@", (ownerPicklistObject?.ownerPicklistFirstname)!, (ownerPicklistObject?.ownerPicklistLastname)!)
}
else
{
ownerName = (ownerPicklistObject?.ownerPicklistFirstname)!
}


var isObjectThere:Bool

if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
isObjectThere = NSUserDefaults.standardUserDefaults().objectForKey("addContactOwnerList")!.containsObject(ownerPicklistObject?.ownerPicklistID)
}


if isObjectThere
{
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
}
else
{
cell.accessoryType = UITableViewCellAccessoryType.None
}

cell.textLabel?.text = ownerName as String
cell.detailTextLabel?.text = ownerPicklistObject?.ownerPicklistEmail

return cell
}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!

if searchBarActive
{
ownerPicklistObject = searchResults![indexPath.row]
}
else
{
ownerPicklistObject = owner![indexPath.row]
}

if cell.accessoryType == UITableViewCellAccessoryType.None
{
cell.accessoryType = UITableViewCellAccessoryType.Checkmark

var ownerName:NSString

if ownerPicklistObject?.ownerPicklistLastname != nil
{
ownerName = NSString (format: "%@ %@", (ownerPicklistObject?.ownerPicklistFirstname)!, (ownerPicklistObject?.ownerPicklistLastname)!)
}
else
{
ownerName = (ownerPicklistObject?.ownerPicklistFirstname)!
}

var isObjectThere:Bool

if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
isObjectThere = NSUserDefaults.standardUserDefaults().objectForKey("addContactOwnerList")!.containsObject(ownerPicklistObject?.ownerPicklistID)
}

if !isObjectThere
{
if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
arSelectedRows?.addObject((ownerPicklistObject?.ownerPicklistID)!)
}
else
{
arSelectedRows?.addObject(ownerName)
}
}
}
else
{
cell.accessoryType = UITableViewCellAccessoryType.None

if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
arSelectedRows?.removeObject((ownerPicklistObject?.ownerPicklistID)!)
}
else
{
arSelectedRows?.removeObject((cell.textLabel?.text)!)
}
}

if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
NSUserDefaults.standardUserDefaults().setObject(arSelectedRows, forKey: "addContactOwnerList")
}

if arSelectedRows?.count == 0
{
if ((backViewController(self)?.isKindOfClass(addContactViewController)) != nil)
{
NSUserDefaults.standardUserDefaults().removeObjectForKey("addContactOwnerList")
}
}

tableView.reloadData()
}

}

最佳答案

var searchBarActive: Bool

您必须显式声明 searchBarActive:

var searchBarActive: Bool?
var searchBarActive: Bool!
var searchBarActive = false

关于ios - 无法弄清楚为什么我得到 "Class has no initializers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37988380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com