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