开发者

Mapkit View with tableview together

I am new to Iphone Dev, seems doesn't really understan开发者_开发百科d 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜