Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:53:30+00:00 2026-06-15T13:53:30+00:00

Right now, our code is set to grab the text from the UITextField as

  • 0

Right now, our code is set to grab the text from the UITextField as setInitialText for Facebook/Twitter posts.

What we want to do is: add an additional permanent message or URL to the Facebook/Twitter posts.

How can we do this? Here’s our current code:

[slComposeThirdViewController setInitialText:[[self QText]text]];

[self presentViewController:slComposeThirdViewController animated:YES completion:nil];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:53:31+00:00Added an answer on June 15, 2026 at 1:53 pm

    It’s a little involved, so bear with me here… and this only works for SLServiceTypeTwitter

    For anyone reading this that is interested in using this, I’ve put a sample project on Github: https://github.com/NSPostWhenIdle/Immutable-SLComposeViewController

    The first thing you’ll want to do is make sure that your view controller conforms to UITextViewDelegate. You’ll also want to create an iVar for a UITextView. You won’t actually be creating a text view, but you’ll want to have a pointer to assign directly to the text view inside the SLComposeViewController. While you’re here make a iVar for the permanent string as well.

    @interface ViewController : UIViewController <UITextViewDelegate> //very important!
    {
        UITextView *sharingTextView;
        NSString *permanentText;
    }
    

    Then in viewDidLoad you can set up what you want the permanent text to be:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        permanentText = @"http://www.stackoverflow.com/";
    }
    

    The code below is a pretty basic IBAction to present the composer with a couple of slight tweaks. First, you’ll notice that setInitialText uses a formatted string the append the permanent text to the end of the contents of the text field with a space added in between.

    Then comes the important part! I’ve added a loop to presentViewController:‘s completion handler to cycle through some subviews of subviews of subviews in order to identify the UITextView in the composer that contains the sharing text. This needs to be done so you can set that text view’s delegate in order to access the UITextViewDelegate method shouldChangeTextInRange.

    - (IBAction)exampleUsingFacebook:(UIButton *)sender {
    
        if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
        {
            SLComposeViewController *sharingComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    
            SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
                [sharingComposer dismissViewControllerAnimated:YES completion:nil];
            };
            [sharingComposer setCompletionHandler:completionHandler];
            [sharingComposer setInitialText:[NSString stringWithFormat:@"%@ %@",[[self QText]text],permanentText]];
    
            [self presentViewController:sharingComposer animated:YES completion:^{
                for (UIView *viewLayer1 in sharingComposer.view.subviews) {
                    for (UIView *viewLayer2 in viewLayer1.subviews) {
                        if ([viewLayer2 isKindOfClass:[UIView class]]) {
                            for (UIView *viewLayer3 in viewLayer2.subviews) {
                                if ([viewLayer3 isKindOfClass:[UITextView class]]) {
                                    [(UITextView *)viewLayer3 setDelegate:self];
                                    sharingTextView = (UITextView *)viewLayer3;
                                }
                            }
                        }
                    }
                }
            }];
        }
    }
    

    Important: Please note that the above will only work if placed in the completion handler.

    Below is an example of how to set up shouldChangeTextInRange to compare the range that the user is attempting to edit to the range that contains your permanent text. By doing so, the user will be able to make changes to any part of the text that they want… except for the part that contains your permanent text. You’ll also notice that inside this method I’ve compared textView to shareingTextView, the pointer we assigned to the text view inside the composer. Doing so will allow you to use other text views within this controller without them following the same rules I’ve configured for the text view inside the composer.

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
        if (textView == sharingTextView) {
            NSRange substringRange = [textView.text rangeOfString:permanentText];
            if (range.location >= substringRange.location && range.location <= substringRange.location + substringRange.length) {
                return NO;
            }
        }
        return YES;
    }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I've just some code which fetches the picture from the URL directly.
We have a script right now which our Windows users run on a Linux
Right now we have AD/Exchange to manage all of our users logins/e-mail on-site at
Our applications use lot of custom built and third party libraries and right now
I don't have the code in front of me right now (but will in
My code right now has O(N) insertion time, and O(1) removal time. I need
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now when I run this it keeps clicking on the same button every
Right now I have a script that will get the last five files in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.