Question

I am new to Iphone Dev, seems doesn't really understand delegate things. Could we put mapkit view and tableview together in one view?

I searched over, and someone said we can't use more than one delegate in one viewcontroller. As I know mapkit require MKMapViewDelegate and tableview require UITableViewDelegate, am I right till this point? Then does it mean, we can't put mapkit and tableview in one view together?

The things that make me also confused, I did simple app that use textview and mapkit together. I only pass MKMapViewDelegate to view controller. But textview also require delegate to close the keypad using textFieldShouldReturn. So i manage to link the delegate from IB file, but did't pass UITextFieldDelegate to view controller. And it works. What is the difference if we link the delegate using IB or pass the delegate param to view controller?

Thanks

Was it helpful?

Solution

A view controller CAN be a delegate for both a map view and a table view. An object becomes a delegate simple by implementing the methods of the delegate protocol, in this case that's MKMapViewDelegate and UITableViewDataSource.

An object can implement any number of protocols. You tell the compiler that instances implement a protocol by adding it to the interface:

@interface MyObject : NSObject <UITableViewDataSource, MKMapViewDelegate>
{
    ...

There is no significant technical difference between setting a delegate in IB and in code. I would advise setting them in IB because using IB reduces the amount of code you write therefore reducing the possibility of your code failing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top