如何設置文本光標在 TWTweetComposeViewController 中的位置? (How to set where the text cursor is in TWTweetComposeViewController?)


問題描述

如何設置文本光標在 TWTweetComposeViewController 中的位置? (How to set where the text cursor is in TWTweetComposeViewController?)

I am using the TWTweetComposeViewController, and when I set the initial text to the title of the screen, the text cursor appears after the hashtag, and I want to have it appear before the hashtag. Is there a way to do something like cursor=(0,0) or something like that? I looked in the documentation and there's nothing there.

For reference, this is what I'm using.

TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc]init];
[tweetSheet setInitialText:[NSString stringWithFormat:@"#%@", self.title]];
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result){
    [self dismissModalViewControllerAnimated:YES];
};
[self presentModalViewController:tweetSheet animated:YES];

‑‑‑‑‑

參考解法

方法 1:

I looked for the exact same thing. It can be done with a little hack. This is the source http://www.sunetos.com/items/2012/06/04/cleanly‑accessing‑the‑uitextview‑field‑in‑twtweetcomposeviewcontroller‑2/

According to the author the app was approved for the app store.

// 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)];
    }
}

Did implement it like this in my app, so if you need further help let me know. 

(by Hudson Buddyjd291)

參考文件

  1. How to set where the text cursor is in TWTweetComposeViewController? (CC BY‑SA 3.0/4.0)

#twitter #iOS #XCode #cursor






相關問題

用於輕鬆創建 Twitter 位置地理坐標的地圖工具? (Map-tool for easily creating Twitter location geo-coordinates?)

PHP Twitter OAuth - 我無法驗證我的帳戶 (PHP Twitter OAuth - I cannot authenticate my account)

如何設置文本光標在 TWTweetComposeViewController 中的位置? (How to set where the text cursor is in TWTweetComposeViewController?)

如何從 Twitter 檢測成功的身份驗證並在此之後運行一些代碼 (How to detect successful authentication from Twitter and run some code after that)

Cocos2d 2.0 升級後 Twitter 不再工作 (Twitter no longer working after Cocos2d 2.0 upgrade)

在 android (eclipse) 中集成 oAuth twitter 時清除共享首選項 (Clearing shared preferences in case of oAuth twitter integration in android (eclipse))

如何在 twitteR R 包的 getUser 中引用變量名? (How to refer a variable name in getUser in twitteR R package?)

使用 twitteR 包提取 Twitter 句柄而不是屏幕名稱? (Extract Twitter Handles instead of Screen Names using twitteR package?)

在白名單 PHP 之後獲取用戶電子郵件 (Get user email afer whitelist PHP)

多久運行一次 cron 來挖掘 Twitter 公共時間線? (How often to run the cron, to mine twitter public timeline?)

如何從 JQuery 發送到 SQL 數據庫? (How to send from JQuery to SQL database?)

使用 facebook、twitter 等進行身份驗證。合而為一! (Authentication with facebook, twitter, etc.. all in one!)







留言討論