사용자 정의 셀에 longPressGesture를 구현했습니다. 이제이 셀에 저장된 정보를 검색해야합니다.Swift - 사용자 정의 tableview-cells에 저장된 정보 검색
내 cellForRowAtIndexPath 기능은 다음과 같습니다
이func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let longPress: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "cellLongPressed:")
longPress.delegate = self
longPress.minimumPressDuration = 1
longPress.numberOfTouchesRequired = 1
let cellID = "cell"
var mcell:CusCell = self.tv.dequeueReusableCellWithIdentifier("cell") as CusCell
mcell.addGestureRecognizer(longPress)
let data = mainList[indexPath.row] as SecondModel
var dateStr:String = String()
dateStr = printDate(data.date)
mcell.mainLabel.text = data.receiver
mcell.recLabel.text = "Message sent at \(dateStr)"
mcell.imageLabel.image = UIImage(named: icons[0])
mcell.messType = messageType
가 반환 을} mcell
내 didSelectRowAtIndexPath 기능은 다음과 같습니다
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedCell: CusCell = tv.cellForRowAtIndexPath(indexPath) as CusCell
messagType = selectedCell.messType
println(messagType)
}
내 cellLongPressed 기능은 다음과 같습니다 :
func cellLongPressed(gestureRecognizer:UIGestureRecognizer) {
if (gestureRecognizer.state == UIGestureRecognizerState.Ended) {
println("STATE ENDED")
//Do Whatever You want on End of Gesture
}
else if (gestureRecognizer.state == UIGestureRecognizerState.Began){
println("STATE BEGAN")
//Do Whatever You want on Began of Gesture
}
}
짐작할 수 있듯이 "selectedCell.messType"에 저장된 정수는 절대로 인쇄되지 않습니다. 왜 이것이 작동하지 않아야하는지, 왜 "selectedCell"에 대한 나의 선언이 잘못 되었는가를 나는 정말로 모른다.
의견을 보내 주시면 감사하겠습니다.
내부의 값을 기록하려면 그 경우 당신은 어디에'messType' 설정됩니다 표시되지 않습니다, 당신은 긴 보도 인식기에 아무것도되지 않습니다. 아마도 cellForRow 메서드의 나머지 부분과 같은 질문에 더 많은 정보를 추가 할 수 있습니까? – jrturton
일반적으로 셀에 데이터를 저장하지 마십시오. 셀은 모델의 데이터를 표시하므로 사물을 저장하는 데 사용하면 안됩니다. – jrturton
@jrturton 제 기능이 추가되었습니다.이 기능이 명확 해지기를 바랍니다. – martin