Created
October 15, 2012 20:25
-
-
Save setoh2000/3895173 to your computer and use it in GitHub Desktop.
Twitter.frameworkやSocial.frameworkのツイート画面でカーソルの初期位置を先頭にする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Twitter/Twitter.h> | |
#import <Social/Social.h> | |
// TWTweetComposeViewControllerの場合 (for iOS5) | |
- (IBAction)tweet:(id)sender | |
{ | |
if ([TWTweetComposeViewController canSendTweet]) { | |
// ツイート用の画面をを表示する | |
TWTweetComposeViewController* composeViewController = [[TWTweetComposeViewController alloc] init]; | |
[composeViewController setInitialText:@"Hello World!"]; | |
[self presentViewController:composeViewController animated:YES completion:^{ | |
[self findTextViewAndMoveToTop:composeViewController.view]; | |
}]; | |
} | |
} | |
// SLComposeViewControllerの場合 (for iOS6) | |
- (IBAction)share:(id)sender | |
{ | |
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { | |
NSString *serviceType = SLServiceTypeTwitter; | |
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:serviceType]; | |
[composeViewController setInitialText:@"Hello World!"]; | |
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) { | |
if (result == SLComposeViewControllerResultDone) { | |
NSLog(@"Done."); | |
} | |
}]; | |
[self presentViewController:composeViewController animated:YES completion:^{ | |
[self findTextViewAndMoveToTop:composeViewController.view]; | |
}]; | |
} | |
} | |
// TextViewが見つかればカーソル位置を先頭にする | |
- (void)findTextViewAndMoveToTop:(UIView *)view | |
{ | |
if ([view isKindOfClass:[UITextView class]]) { | |
UITextView *textView = (UITextView *)view; | |
textView.selectedRange = NSMakeRange(0, 0); | |
return; | |
} | |
for (UIView *subview in [view subviews]) { | |
[self findTextViewAndMoveToTop:subview]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ARC環境の方はselfを__weakな変数に代入してから呼び出さないと循環参照になる可能性があるのでご注意下さい。