Commit ceef5261d94db1ed0d0f0a8d1ac41630399c00c7

Authored by bryan ago
1 parent 9d9cd5b045
Exists in master

Implement tweet write view controller

Showing 1 changed file with 22 additions and 2 deletions Inline Diff

TwitterKitExample/TWListViewController.m View file @ ceef526
// 1 1 //
// TWListViewController.m 2 2 // TWListViewController.m
// TwitterKitExample 3 3 // TwitterKitExample
// 4 4 //
// Created by DongSoo Lee on 2015. 12. 8.. 5 5 // Created by DongSoo Lee on 2015. 12. 8..
// Copyright © 2015년 DongSoo Lee. All rights reserved. 6 6 // Copyright © 2015년 DongSoo Lee. All rights reserved.
// 7 7 //
8 8
#import "TWListViewController.h" 9 9 #import "TWListViewController.h"
#import <TwitterKit/TwitterKit.h> 10 10 #import <TwitterKit/TwitterKit.h>
#import "TWTimelineViewController.h" 11 11 #import "TWTimelineViewController.h"
#import "TWComposeViewController.h" 12 12 #import "TWComposeViewController.h"
13 13
@interface TWListViewController() 14 14 @interface TWListViewController()
15 15
@property (assign, nonatomic) NSInteger tweetCount; 16 16 @property (assign, nonatomic) NSInteger tweetCount;
@property (strong, nonatomic) NSArray *tweetArray; 17 17 @property (strong, nonatomic) NSArray *tweetArray;
18 18
@property (strong, nonatomic) UITableView *tableView; 19 19 @property (strong, nonatomic) UITableView *tableView;
20 20
@end 21 21 @end
22 22
@implementation TWListViewController 23 23 @implementation TWListViewController
24 24
- (void) viewDidLoad { 25 25 - (void) viewDidLoad {
[super viewDidLoad]; 26 26 [super viewDidLoad];
27 27
self.edgesForExtendedLayout = UIRectEdgeNone; 28 28 self.edgesForExtendedLayout = UIRectEdgeNone;
29 29
self.title = @"트위터 싱글뷰"; 30 30 self.title = @"트위터 싱글뷰";
31 31
TWTRTweetView *tweetView = [[TWTRTweetView alloc] init]; 32 32 TWTRTweetView *tweetView = [[TWTRTweetView alloc] init];
tweetView.showActionButtons = YES; 33 33 tweetView.showActionButtons = YES;
34 34
__weak typeof(self) wself = self; 35 35 __weak typeof(self) wself = self;
TWTRAPIClient *client = [[TWTRAPIClient alloc] init]; 36 36 TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
[client loadTweetWithID:@"20" completion:^(TWTRTweet * _Nullable tweet, NSError * _Nullable error) { 37 37 [client loadTweetWithID:@"20" completion:^(TWTRTweet * _Nullable tweet, NSError * _Nullable error) {
if (tweet) { 38 38 if (tweet) {
[tweetView configureWithTweet:tweet]; 39 39 [tweetView configureWithTweet:tweet];
40 40
[wself.view addSubview:tweetView]; 41 41 [wself.view addSubview:tweetView];
42 42
[wself congifureTableView:tweetView.frame]; 43 43 [wself congifureTableView:tweetView.frame];
} else { 44 44 } else {
NSLog(@"Failed to load tweet: %@", [error localizedDescription]); 45 45 NSLog(@"Failed to load tweet: %@", [error localizedDescription]);
} 46 46 }
}]; 47 47 }];
48 48
[client loadTweetsWithIDs:@[@"20"] completion:^(NSArray * _Nullable tweets, NSError * _Nullable error) { 49 49 [client loadTweetsWithIDs:@[@"20"] completion:^(NSArray * _Nullable tweets, NSError * _Nullable error) {
if (tweets) { 50 50 if (tweets) {
wself.tweetArray = [NSArray arrayWithArray:tweets]; 51 51 wself.tweetArray = [NSArray arrayWithArray:tweets];
52 52
wself.tweetCount = tweets.count; 53 53 wself.tweetCount = tweets.count;
[wself.tableView reloadData]; 54 54 [wself.tableView reloadData];
} else { 55 55 } else {
NSLog(@"Failed to load tweet: %@", [error localizedDescription]); 56 56 NSLog(@"Failed to load tweet: %@", [error localizedDescription]);
} 57 57 }
}]; 58 58 }];
59 59
UIImage *image = [UIImage imageNamed:@"TwitterKitResources.bundle/twtr-icn-logo.png"]; 60 60 UIImage *image = [UIImage imageNamed:@"TwitterKitResources.bundle/twtr-icn-logo.png"];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)]; 61 61 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[button setImage:image forState:UIControlStateNormal]; 62 62 [button setImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(moveToWrite) forControlEvents:UIControlEventTouchUpInside]; 63 63 [button addTarget:self action:@selector(moveToCompose) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *temp = [[UIBarButtonItem alloc] initWithCustomView:button]; 64 64 UIBarButtonItem *temp = [[UIBarButtonItem alloc] initWithCustomView:button];
65 65
NSArray *rightItemArray = @[temp 66 66 NSArray *rightItemArray = @[temp
, [[UIBarButtonItem alloc] initWithTitle:@"타임라인" style:UIBarButtonItemStylePlain target:self action:@selector(moveToTimeline)]]; 67 67 , [[UIBarButtonItem alloc] initWithTitle:@"타임라인" style:UIBarButtonItemStylePlain target:self action:@selector(moveToTimeline)]];
[self.navigationItem setRightBarButtonItems:rightItemArray]; 68 68 [self.navigationItem setRightBarButtonItems:rightItemArray];
69 69
70 [self addWriteViewController];
} 70 71 }
71 72
- (void) moveToTimeline { 72 73 - (void) moveToTimeline {
TWTimelineViewController *vc = [[TWTimelineViewController alloc] init]; 73 74 TWTimelineViewController *vc = [[TWTimelineViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES]; 74 75 [self.navigationController pushViewController:vc animated:YES];
} 75 76 }
76 77
- (void) moveToWrite { 77 78 - (void) moveToCompose {
TWComposeViewController *vc = [[TWComposeViewController alloc] init]; 78 79 TWComposeViewController *vc = [[TWComposeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES]; 79 80 [self.navigationController pushViewController:vc animated:YES];
81 }
82
83 - (void) moveToWrite {
84 TWTRSession *session = [Twitter sharedInstance].sessionStore.session;
85
86 TWTRCardConfiguration *card = [TWTRCardConfiguration appCardConfigurationWithPromoImage:nil iPhoneAppID:@"12345" iPadAppID:nil googlePlayAppID:nil];
87 TWTRComposerViewController *vc = [[TWTRComposerViewController alloc] initWithUserID:session.userID cardConfiguration:card];
88
89 vc.delegate = self;
90
91 [self.navigationController presentViewController:vc animated:YES completion:nil];
92 }
93
94 - (void) addWriteViewController {
95 UIImage *image = [UIImage imageNamed:@"TwitterKitResources.bundle/twtr-icn-logo-white.png"];
96 UIButton *tweetWriteButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - image.size.width*2 - 20, self.view.bounds.size.height - image.size.height*2 - 120, image.size.width*2, image.size.height*2)];
97 [tweetWriteButton setBackgroundImage:image forState:UIControlStateNormal];
98 [tweetWriteButton addTarget:self action:@selector(moveToWrite) forControlEvents:UIControlEventTouchUpInside];
99 [self.view addSubview:tweetWriteButton];
} 80 100 }
81 101
- (void) congifureTableView:(CGRect) frame { 82 102 - (void) congifureTableView:(CGRect) frame {
83 103
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, frame.origin.y+frame.size.height+50 84 104 self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, frame.origin.y+frame.size.height+50
, self.view.bounds.size.width, 300)]; 85 105 , self.view.bounds.size.width, 300)];
[self.view addSubview:self.tableView]; 86 106 [self.view addSubview:self.tableView];
87 107
self.tableView.delegate = self; 88 108 self.tableView.delegate = self;
self.tableView.dataSource = self; 89 109 self.tableView.dataSource = self;
90 110
[self.tableView registerClass:[TWTRTweetTableViewCell class] forCellReuseIdentifier:@"tweetTableViewCell"]; 91 111 [self.tableView registerClass:[TWTRTweetTableViewCell class] forCellReuseIdentifier:@"tweetTableViewCell"];
} 92 112 }
93 113
- (TWTRTweetTableViewCell *) configureTableViewCell:(TWTRTweetTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *) indexPath { 94 114 - (TWTRTweetTableViewCell *) configureTableViewCell:(TWTRTweetTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *) indexPath {
95 115