lukescott / TimelineView

TimelineView functions like a UITableView, but allows you to position cells anywhere using a custom frame (CGRect). This allows you to have irregular spacing, overlapping cells, etc...
MIT License
42 stars 13 forks source link

Protocol Definition of TimelineViewDelegate #7

Open Obbut opened 10 years ago

Obbut commented 10 years ago

The protocol definition of TimelineViewDelegate currently looks like this:

@protocol TimelineViewDelegate <NSObject>
...
@end

Because TimelineView inherits from UIScrollView, and UIScrollView already has a property 'delegate', you require every class that is a TimelineViewDelegate to also explicitly be a UIScrollViewDelegate:

@interface TimelineView : UIScrollView
...
@property (weak, nonatomic) IBOutlet id<TimelineViewDelegate,UIScrollViewDelegate>delegate;
...
@end

However, if you would let the TimelineViewDelegate protocol inherit from UIScrollViewDelegate, you could overcome this 'issue', and thus requiring less unneccessary code.

If we change the protocol definition to this:

@protocol TimelineViewDelegate <NSObject, UIScrollViewDelegate>

And make this change in TimelineView.h:

@property (weak, nonatomic) IBOutlet id<TimelineViewDelegate,UIScrollViewDelegate>delegate;

In your sample code, the delegate and dataSource are set via interface builder, which is why no warning is given when compiling the sample project -- even though ViewController does not conform to the UIScrollViewDelegate protocol. When setting the data source and/or the delegate programmatically, however, a compile warning is given.

ethansinjin commented 8 years ago

Slightly off topic, but I thought I'd mention something here: there may be times where it's desirable to set the UIScrollViewDelegate and the TimelineViewDelegate separately (such as for synchronizing scrolling between timeline views). Perhaps splitting up the delegate would work as well?