나는 컬렉션보기와 버튼이 있습니다. 이 버튼을 누르면 이름을 변경하고 싶습니다. 나는 그것을 할 수 있었지만 내가 탭할 때 20 개의 버튼이 있다면 10 개가 바뀐다. 첫 번째 버튼을 탭하면 0,2,4,6,8이 바뀌고, 목록에 없으면 모든 버튼이 선택됩니다. 내가 너무 if 문없이 시도셀 안의 버튼의 제목을 변경하는 방법 Swift
@IBAction func following(sender: AnyObject) {
if follow.tag == sender.tag {
follow.setTitle("Following", forState: .Normal)
}
print("\(follow.tag) \(sender.tag)")
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Interest Cell", forIndexPath: indexPath) as! ThirdTabCell
cell.follow.tag = indexPath.row
return cell
}
버튼의 함수 내부 그러나 다시 같은 문제 :
이 내 코드입니다. 태그를 인쇄하면 탭 한 단추 만 인쇄됩니다.
나는 또한 나의의 ViewController에
cell.follow.addTarget(self, action: #selector(ThirdTab.follow(_:)), forControlEvents: UIControlEvents.TouchUpInside)
//inside cellForItemAtIndexPath
func follow(sender:UIButton!) {
}
어디서 다음()을 요청할 수 있습니까? 재사용 가능한 셀에서 IBAction을 가질 수 없어야합니다. 또한 보낸 사람이 AnyObject 대신 UIButton이어야한다고 가정합니다. – Happiehappie
ibaction 함수가 셀 클래스 내부에 있음 –
VC에서 선택기 메서드를 만드는 것이 좋습니다. – Happiehappie