1 //
2 // TWTRTimelineViewController.h
3 // TwitterKit
4 //
5 // Copyright (c) 2015 Twitter. All rights reserved.
6 //
7
8 #import <UIKit/UIKit.h>
9 @protocol TWTRTimelineDataSource;
10 @protocol TWTRTweetViewDelegate;
11 @protocol TWTRTimelineDelegate;
12 @class TWTRMoPubAdConfiguration;
13
14 NS_ASSUME_NONNULL_BEGIN
15
16 /**
17 This class is a `UITableViewController` subclass that displays `TWTRTweetTableViewCell` cells. It handles cell-reuse, cell-configuration, and loading more Tweets from the given timeline once the last cell is displayed.
18
19 ## Usage
20
21 Initialize this class with any object that conforms to the `TWTRTimelineDataSource` protocol. We provide two such classes, `TWTRUserTimelineDataSource` and `TWTRSearchTimelineDataSource`. These provide `TWTRTweet` objects to this table view which then configures the instances of `TWTRTweetTableViewCell`.
22
23 // Create the data source
24 TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
25 TWTRUserTimelineDataSource *dataSource = [[TWTRUserTimelineDataSource alloc] initWithScreenName:@"jack" APIClient:client];
26
27 // Create the timeline view controller
28 TWTRTimelineViewController *timeline = [[TWTRTimelineViewController alloc] initWithDataSource:dataSource];
29
30 ## Loading More
31
32 This class loads the first batch of `TWTRTweet` objects from the Twitter API when `viewWillAppear:` is received. It also handles loading more tweets automatically once the last cell has been shown.
33
34 */
35 @interface TWTRTimelineViewController : UITableViewController
36
37 /**
38 The source of `TWTRTweet` objects for this `TWTRTimelineViewController`.
39 May be set to update the Tweets being shown by this table view. Must be set on the main thread.
40 */
41 @property (nonatomic, copy) id<TWTRTimelineDataSource> dataSource;
42
43 /**
44 * The configuration of MoPub ads to show in the timeline. You must
45 * link against the MoPub framework and provide this configuration in order
46 * for ads to be injected.
47 * @note Changing this will force a reload of the timeline. You can only set this once. Must be set on the main thread.
48 */
49 @property (nonatomic, nullable) TWTRMoPubAdConfiguration *adConfiguration;
50
51 /**
52 * Whether action buttons (Like, Share) should be shown on the `TWTRTweetTableViewCell`s inside the tableview.
53 */
54 @property (nonatomic) BOOL showTweetActions;
55
56 /**
57 * If set, this value will be passed to all TWTRTweetView instances in the timeline.
58 */
59 @property (nonatomic, weak) id<TWTRTweetViewDelegate> tweetViewDelegate;
60
61 /**
62 * The object that acts as the delegate for the timeline.
63 */
64 @property (nonatomic, weak) id<TWTRTimelineDelegate> timelineDelegate;
65
66 /**
67 Initializes a timeline view controller. Does not start loading tweets until
68 `viewWillAppear:` is called.
69
70 This method must be used to initialize this class. The `init` method is unavailable.
71
72 @param dataSource A timeline data source object that conforms to the `TWTRTimelineDataSource` protocol.
73
74 @return A fully initialized `TWTRTimelineViewController` or nil if the data source is missing.
75 */
76 - (instancetype)initWithDataSource:(nullable id<TWTRTimelineDataSource>)dataSource;
77
78 /**
79 * Initializes a timeline view controller with an optional ad configuration. Does not start loading Tweets until `viewWillAppear:` is called.
80 *
81 * @param dataSource A timeline data source object that conforms to the `TWTRTimelineDataSource` protocol.
82 * @param adConfiguration Configuration for the type of MoPub ads to display. Ads will only load after
83 * the initial timeline is loaded. No ads will be displayed if nil.
84 *
85 * @return A fully initialized `TWTRTimelineViewController`. Tweets will not be loaded if the data source is nil.
86 */
87 - (instancetype)initWithDataSource:(nullable id<TWTRTimelineDataSource>)dataSource adConfiguration:(nullable TWTRMoPubAdConfiguration *)adConfiguration;
88
89 - (instancetype)initWithStyle:(UITableViewStyle)style NS_UNAVAILABLE;
90
91 /**
92 * Asynchronously refresh and replace all the data in the table view with the latest `TWTRTweet`s.
93 */
94 - (void)refresh;
95
96 /**
97 * Returns the number of Tweets that are currently displayed by the controller.
98 */
99 - (NSUInteger)countOfTweets;
100
101 /**
102 * Returns the Tweet at the given index.
103 *
104 * @warning This method will throw an exception if the index is out of range of the count of Tweets.
105 */
106 - (TWTRTweet *)tweetAtIndex:(NSInteger)index;
107
108 /**
109 * Returns a copy of the Tweets at the time of calling this method.
110
111 * This method returns the copy of the current Tweets. The Tweets may change
112 * after this method is called.
113 */
114 - (NSArray *)snapshotTweets;
115
116 @end
117
118 NS_ASSUME_NONNULL_END
119