ios – 如何使用swift代碼在按鈕單擊中在自定義UITableViewCell中顯示UIAlertController?

    我想在按鈕單擊中在自定義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)}

    以上是來客網(wǎng)為你收集整理得ios – 如何使用swift代碼在按鈕單擊中在自定義UITableViewCell中顯示UIAlertController?全部內(nèi)容,希望內(nèi)容能夠幫你解決ios – 如何使用swift代碼在按鈕單擊中在自定義UITableViewCell中顯示UIAlertController?所遇到得程序開發(fā)問題。

    如果覺得來客網(wǎng)網(wǎng)站內(nèi)容還不錯,歡迎將來客網(wǎng)網(wǎng)站推薦給程序員好友。

    聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。
    發(fā)表評論
    更多 網(wǎng)友評論1 條評論)
    暫無評論

    返回頂部

    主站蜘蛛池模板: 精品国产一区二区三区在线观看| 亚欧免费视频一区二区三区| 中文字幕一区二区三区免费视频 | 国产成人精品第一区二区| 波多野结衣中文字幕一区| 在线观看日本亚洲一区| 无码国产精成人午夜视频一区二区| 国产成人高清视频一区二区| 无码人妻久久一区二区三区免费丨| 无码国产精品一区二区免费模式| 肥臀熟女一区二区三区| 亚洲人成网站18禁止一区| 女同一区二区在线观看| 国产精品久久久久久一区二区三区 | 亚洲美女一区二区三区| 精品乱子伦一区二区三区高清免费播放 | 国产成人精品一区二区秒拍| 无码精品人妻一区二区三区免费| 日韩免费无码一区二区视频| 影院成人区精品一区二区婷婷丽春院影视 | 3d动漫精品成人一区二区三| 水蜜桃av无码一区二区| 久久99精品波多结衣一区| 亚洲日韩激情无码一区| 久久亚洲综合色一区二区三区 | 日韩精品视频一区二区三区| 精品性影院一区二区三区内射 | 色久综合网精品一区二区| 肉色超薄丝袜脚交一区二区| 精品无码av一区二区三区| 午夜天堂一区人妻| 任你躁国语自产一区在| 精品爆乳一区二区三区无码av| 3D动漫精品啪啪一区二区下载 | 色窝窝无码一区二区三区成人网站| 一区二区三区在线|欧| 国产精品视频一区二区三区| 无码丰满熟妇一区二区| 免费国产在线精品一区| 国产在线精品一区二区不卡| tom影院亚洲国产一区二区|