gpt4 book ai didi

swift - DidSelectRowAtIndexPath 根本没有被调用

转载 作者:可可西里 更新时间:2023-11-01 00:59:20 24 4
gpt4 key购买 nike

<分区>

我已经设置了 tableview.delegate = self...从 donut 拖到委托(delegate)和数据源....处理协议(protocol)和其他一切但是当我选择一个单元格时它不会被调用。我设置了一个断点并进行了打印,但没有任何反应

enter image description here 导入 UIKit

class StartCompetitionViewController: UIViewController, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource {



@IBOutlet weak var mainStackView: UIStackView!

@IBOutlet weak var pickThemeLabel: UILabel!

@IBOutlet weak var themeTextField: UITextField!
@IBOutlet weak var tableView: UITableView!

@IBOutlet weak var middleStackView: UIStackView!
@IBOutlet weak var logoStackView: UIStackView!
@IBOutlet weak var buttonStackView: UIStackView!

@IBOutlet weak var leftOrTopButton: UIButton!
@IBOutlet weak var rightOrBottomButton: UIButton!


var autoComplete = [String]()

override func viewDidLoad() {
super.viewDidLoad()




leftOrTopButton.landingPageButtonsRound()
leftOrTopButton.setTitle("Back", forState: .Normal)
leftOrTopButton.backgroundColor = UIColor(red: 239.0/255.0, green: 77.0/255.0, blue: 77.0/255.0, alpha: 1.0)

rightOrBottomButton.landingPageButtonsRound()
rightOrBottomButton.setTitle("Next", forState: .Normal)
rightOrBottomButton.backgroundColor = UIColor(red: 249.0/255.0, green: 214.0/255.0, blue: 0.0/155.0, alpha: 1.0)

pickThemeLabel.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
pickThemeLabel.text = "Pick a Theme"
pickThemeLabel.textColor = UIColor.whiteColor()


view.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)


themeTextField.keyboardAppearance = .Dark
themeTextField.autocorrectionType = .No



leftOrTopButton.setTitle("Back", forState: .Normal)

rightOrBottomButton.setTitle("Next", forState: .Normal)

slowFadeInMiddleInformation()


themeTextField.delegate = self
themeTextField.backgroundColor = UIColor.whiteColor()

//tableView.delegate = self

    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None



NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(StartCompetitionViewController.keyboardWillShow(_:)), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(StartCompetitionViewController.keyboardWillHide(_:)), name:UIKeyboardWillHideNotification, object: nil);


hideKeyboardWhenTappedAround()


}


@objc func keyboardWillShow(sender: NSNotification) {

view.frame.origin.y = -170

}
@objc func keyboardWillHide(sender: NSNotification) {

view.frame.origin.y = 0

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


func textFieldShouldEndEditing(textField: UITextField) -> Bool {

self.themeTextField.resignFirstResponder()

return true
}

func textFieldShouldReturn(textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}

func slowFadeInMiddleInformation(){

self.middleStackView.alpha = 0.0

UIView.animateWithDuration(0.5,
delay: 0.0,
options: .CurveLinear,
animations: {


self.middleStackView.alpha = 1.0




}, completion: nil)

}


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


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

let index = indexPath.row as Int

cell.textLabel!.text = autoComplete[index]



cell.textLabel!.font = UIFont(name:"Helvetica", size: 24)
cell.textLabel?.textAlignment = .Center
cell.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
cell.textLabel?.textColor = UIColor.whiteColor()


return cell

}

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

let substring = (textField.text!.lowercaseString as NSString).stringByReplacingCharactersInRange(range, withString: string)

substring.lowercaseString

searchAutocompleteEntriesWithSubstring(substring.lowercaseString)


if textField == themeTextField{
_ = range.length == 0 ? textField.text! + string : (themeTextField.text! as NSString).stringByReplacingCharactersInRange(range, withString: string)



}

return true

}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return autoComplete.count

}

func searchAutocompleteEntriesWithSubstring(substring: String) {

autoComplete.removeAll(keepCapacity: false)

for key in LocalModal().possibleThemesArray {

let myString: NSString! = key.lowercaseString as NSString

let substringRange :NSRange! = myString.rangeOfString(substring)

if (substringRange.location == 0) {
autoComplete.append(key)
}

}

tableView.reloadData()

}




func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


let selectedCell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!

themeTextField.text = selectedCell.textLabel!.text!

autoComplete.removeAll(keepCapacity: false)

tableView.reloadData()

print("foo")
}



func animateEverythingBack(){

UIView.animateWithDuration(1.5,
delay: 0.0,
options: .CurveLinear,
animations: {



self.middleStackView.center.y += self.view.bounds.width


self.buttonStackView.center.y += self.view.bounds.width






}, completion: nil)

}

func fadeOutOfMiddleStackView(){

UIView.animateWithDuration(0.5,
delay: 0.0,
options: .CurveLinear,
animations: {

self.middleStackView.alpha = 0.0

}, completion: nil)

}



@IBAction func leftOrTopButtonTapped(sender: UIButton) {


animateEverythingBack()
fadeOutOfMiddleStackView()

delay(1.6) {
self.performSegueWithIdentifier("fromStartToLanding", sender: self)
}



}

@IBAction func bottomOrRightButtonTapped(sender: UIButton) {

self.performSegueWithIdentifier("fromStartToWillJoin", sender: self)

}

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