airsoftFreak
airsoftFreak

Reputation: 1608

How do i add delegate to an object in tableViewCell?

In View Controller there is viewDidLoad where I could add delegate and so on, for example

override func viewDidLoad() {
        super.viewDidLoad()
        // for example
        tableView.delegate = self
}

In tableViewCell , the only default method that has been created is

@IBOutlet var mapView: GMSMapView!
 // This method
 override func awakeFromNib() {
        super.awakeFromNib()
    }

Because I really need to add delegate to the map.

Upvotes: 0

Views: 79

Answers (1)

Konstantin
Konstantin

Reputation: 861

if your use UIBTableView and you need to set delegate to some of objects in UITableViewCell than best way to do it in

-(UITableViewCell)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

but you shouldn't forget to clear delegate, best way to do it in your subclass of UITableViewCell

-(void)prepareForReuse;

In Swift

func tableView(_ tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

override func prepareForReuse()

Upvotes: 1

Related Questions