Skip to content

Commit 8028a0c

Browse files
committed
Handle @twitter handler tap by calling TwitterFollowDelegate delegate
1 parent f46cb24 commit 8028a0c

6 files changed

+24
-12
lines changed

trySwift/OfficeHoursDetailViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension OfficeHoursDetailViewController {
4747
return cell
4848
case .speakerInfo:
4949
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
50-
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false)
50+
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false, delegate: self)
5151
return cell
5252
case .bio:
5353
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell

trySwift/SessionDetailsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension SessionDetailsViewController {
4949
return cell
5050
case .speakerInfo:
5151
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
52-
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false)
52+
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false, delegate: self)
5353
return cell
5454
case .summary:
5555
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell

trySwift/SpeakerDetailViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension SpeakerDetailViewController {
4343
switch SpeakerDetail(rawValue: indexPath.row)! {
4444
case .header:
4545
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
46-
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false)
46+
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false, delegate: self)
4747
return cell
4848
case .bio:
4949
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell

trySwift/SpeakerTableViewCell.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,31 @@ class SpeakerTableViewCell: UITableViewCell {
1414

1515
@IBOutlet weak var speakerImageView: UIImageView!
1616
@IBOutlet weak var speakerNameLabel: UILabel!
17-
@IBOutlet weak var speakerTwitterLabel: UILabel!
18-
17+
@IBOutlet weak var speakerTwitterButton: UIButton!
18+
19+
fileprivate var speaker: Speaker?
20+
fileprivate weak var delegate: TwitterFollowDelegate?
21+
1922
override func awakeFromNib() {
2023
super.awakeFromNib()
21-
22-
speakerTwitterLabel.textColor = .trySwiftAccentColor()
24+
speakerTwitterButton.setTitleColor(.trySwiftAccentColor(), for: .normal)
2325
}
2426

25-
func configure(withSpeaker speaker: Speaker, selectionEnabled: Bool = true, accessoryEnabled: Bool = true) {
2627

28+
@IBAction func speakerTwitterButtonDidTap(_ sender: Any) {
29+
guard let speaker = speaker else {
30+
assertionFailure("Speaker is not set")
31+
return
32+
}
33+
self.delegate?.followUser(speaker.twitter)
34+
}
35+
36+
func configure(withSpeaker speaker: Speaker, selectionEnabled: Bool = true, accessoryEnabled: Bool = true, delegate: TwitterFollowDelegate) {
2737
let scale = UIScreen.main.scale
2838
let processor = RoundCornerImageProcessor(cornerRadius: 34, targetSize: CGSize(width: 67, height: 67))
2939
speakerImageView.kf.setImage(with: speaker.imageURL, placeholder: nil, options: [.processor(processor), .scaleFactor(scale)])
3040
speakerNameLabel.text = speaker.localizedName
31-
speakerTwitterLabel.text = "@\(speaker.twitter)"
32-
41+
speakerTwitterButton.setTitle("@\(speaker.twitter)", for: .normal)
3342
if !selectionEnabled {
3443
selectionStyle = .none
3544
}
@@ -40,5 +49,8 @@ class SpeakerTableViewCell: UITableViewCell {
4049

4150
setNeedsUpdateConstraints()
4251
layoutIfNeeded()
52+
53+
self.speaker = speaker
54+
self.delegate = delegate
4355
}
4456
}

trySwift/SpeakersViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extension SpeakersViewController {
7272
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
7373
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
7474

75-
cell.configure(withSpeaker: speakers[indexPath.row])
75+
cell.configure(withSpeaker: speakers[indexPath.row], delegate: self)
7676

7777
return cell
7878
}

trySwift/WorkshopDetailViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension WorkshopDetailViewController {
5656
return cell
5757
case .speakerInfo:
5858
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
59-
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false)
59+
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false, delegate: self)
6060
return cell
6161
case .summary:
6262
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell

0 commit comments

Comments
 (0)