ios – 如何使用swift代码在按钮单击中在自定义UITableViewCell中显示UIAlertController?

ios – 如何使用swift代码在按钮单击中在自定义UITableViewCell中显示UIAlertController?,第1张

概述我想在按钮单击中在自定义UITableViewCell中显示UIAlertController.但我找不到任何办法.请看下面我试过的代码. 此代码在UITableViewCel中给出错误,如上图所示. 请帮帮我.全班代码如下: class CustomCellDeerCalls: UITableViewCell {override func awakeFromNib() { super 我想在按钮单击中在自定义UItableVIEwCell中显示UIAlertController.但我找不到任何办法.请看下面我试过的代码.

此代码在UItableVIEwCel中给出错误,如上图所示.
请帮帮我.全班代码如下:

class CustomCellDeerCalls: UItableVIEwCell {overrIDe func awakeFromNib() {    super.awakeFromNib()    // Initialization code}@IBOutlet weak var playbutton: UIbutton!@IBOutlet weak var detialsInfobutton: UIbutton!@IBOutlet weak var DeerCallnameLabel: UILabel!var arrayOfDetialsInfoDeerCalls: [String]=["This sound is a doe's way of locating other deer of her family group . This call can be used all year long.","Grunts are a doe's way of saying come here,also to call her fawns at Feeding time . It is critical to keep the call soft as a loud grunt is too aggressive of a call.","A buck grunt is a deeper pitch than a doe grunt,it means the same thing . The older the buck the deeper the tone. ","As the buck chases the doe as the rut approaches he is frustrated,and makes a serIEs of soft grunts while trailing her. It's the bucks way of asking her to stop so he can be breed with her.","This sound's a lot like a calf bawl,but it is a serIEs of buck bleats. This signals the bucks desire for company.","This is a non aggressive and social behavIoUr that all bucks do after shedding their velvet . This is when the bucks learn who can whip the other . This process does not prevent serIoUs fights later on during the rut.","This is the sound that a buck makes during the courtship when the doe stops running,but won't let the buck breed her. It's a non aggressive and frustration call by him.","This is the sound that a Doe makes to signal that her breeding time is near.","This is the sound that a Doe makes to signal that she ready to breed RIGHT Now.","Deer make this sound to intimIDate other deer and prevent fights. This call is often made by a rut- crazed buck when confronted with a rival. This sound can send smaller buck running from the area.","Another rut crazed Bucks sound to intimIDate other deer and prevent fights when confronted with a rival. This sound can also send smaller buck running from the area.","This is a short aggressive rattling sequence to possibly lure in less aggressive,but curIoUs buck,as well as the local dominant whitetail buck of the area. To make this sound like a real fight sniffs,wheezes and grunts have also been thrown in for added effect."]var arrayOfDeerSoundsCall: [String]=["CONTACT","doegrunt","bkgrunt","tend","bawl","spar","rage","estrusb","bellow","sniff","wheeze","rattle"]

// var arrayOfCallsname:[String] = [“”]

@IBAction func clickDetialsInfobutton(sender: AnyObject) {   var alert = UIAlertController(Title: "dddddd",message: arrayOfDetialsInfoDeerCalls[sender.tag],preferredStyle: UIAlertControllerStyle.Alert)   alert.addAction(UIAlertAction(Title: "OK",style: UIAlertActionStyle.Default,handler: nil))self.presentVIEwController(alert,animated: true,completion: nil)    //sender.sup   //}var audioPlayer = AVAudioPlayer()@IBAction func clickplaybutton(sender: AnyObject) {    println(sender.tag)    var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(arrayOfDeerSoundsCall[sender.tag],ofType: "wav")!)    println(alertSound)    // Removed deprecated use of AVAudioSessionDelegate protocol    AVAudioSession.sharedInstance().setcategory(AVAudioSessioncategoryPlayback,error: nil)    AVAudioSession.sharedInstance().setActive(true,error: nil)    var error:NSError?    audioPlayer = AVAudioPlayer(contentsOfURL: alertSound,error: &error)    audioPlayer.preparetoPlay()    audioPlayer.play()}overrIDe func setSelected(selected: Bool,animated: Bool) {    super.setSelected(selected,animated: animated)    // Configure the vIEw for the selected state}func setCell(callname: String){self.DeerCallnameLabel.text=callname}

}

解决方法 我找到了解决方案.以下是上述问题的代码.
在vIEwcontroller中为按钮编写以下代码,其中存在表视图.
func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {    let deernameCell: CustomCellDeerCalls = tableVIEw.dequeueReusableCellWithIDentifIEr("Cell") as CustomCellDeerCalls    let deercallcell=arrayOfCallsname[indexPath.row]    deernameCell.DeerCallnameLabel.text=deercallcell.callname    deernameCell.playbutton.tag=indexPath.row    deernameCell.detialsInfobutton.tag=indexPath.row    deernameCell.detialsInfobutton.addTarget(self,action: "showAlert:",forControlEvents:UIControlEvents.touchUpInsIDe)    return deernameCell}

和相同视图控制器中的警报功能:

func showAlert(sender:UIbutton!){    println(sender.tag)    let deercallcell=arrayOfCallsname[sender.tag]    var alert = UIAlertController(Title: deercallcell.callname,preferredStyle: UIAlertControllerStyle.Alert)    alert.addAction(UIAlertAction(Title: "OK",handler: nil))    self.presentVIEwController(alert,completion: nil)}
总结

以上是内存溢出为你收集整理的ios – 如何使用swift代码在按钮单击中在自定义UITableViewCell中显示UIAlertController?全部内容,希望文章能够帮你解决ios – 如何使用swift代码在按钮单击中在自定义UITableViewCell中显示UIAlertController?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1114046.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存