我正在使用TWTweetComposeViewController,当我将初始文本设置为屏幕标题时,文本光标出现在主题标签之后,并且我希望它出现在主题标签之前。有没有办法做类似cursor =(0,0)之类的事情?我查看了文档,那里什么也没有。
供参考,这是我正在使用的。
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc]init];
[tweetSheet setInitialText:[NSString stringWithFormat:@"#%@", self.title]];
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result){
[self dismissModalViewControllerAnimated:YES];
};
[self presentModalViewController:tweetSheet animated:YES];
最佳答案
我寻找完全相同的东西。只需一点技巧即可完成。这是源http://www.sunetos.com/items/2012/06/04/cleanly-accessing-the-uitextview-field-in-twtweetcomposeviewcontroller-2/
根据作者的说法,该应用已获准进入应用商店。
// at an appropriate place in your code,
// add and remove the observer for UIKeyboardWillShowNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleKeyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
- (UIView *) findFirstResponderInView:(UIView*) view
{
if (view.isFirstResponder) {
return view;
}
for (UIView *subview in view.subviews) {
UIView *result = [self findFirstResponderInView:subview];
if (result) {
return result;
}
}
return nil;
}
- (void) handleKeyboardWillShow:(NSNotification *) notification;
{
UIView *fr = [self findFirstResponder:self.tweetSheetViewController.view];
if ([fr isKindOfClass:[UITextView class]]) {
UITextView *tv = (UITextView *) fr;
[tv setSelectedRange:NSMakeRange(0,0)];
}
}
确实在我的应用中实现了这样的功能,所以如果您需要进一步的帮助,请告诉我。