I have made a random fact generator and was wondering if i could make the initial text in a tweet from the app the same as whatever the label (which is where the fact i going to be displayed when the user pushes a button) says. Help would be greatly appreciated, and i am new semi new to coding but just really need help on this one part. If you need more info about what i am asking just leave a comment. thanks

This is the code that i would use to generate the tweet (if i knew how to make the initial text a variable) What i have with stars around it is what i want to have changed :

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    SLComposeViewController *twitter = [[SLComposeViewController alloc] init];

    twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    [twitter setInitialText:[NSString stringWithFormat:@"***Say Something***"]];
    [self presentViewController:twitter animated:YES completion:nil];

    [twitter setCompletionHandler:^(SLComposeViewControllerResult result) {
        NSString *output;
        switch (result) {
            case SLComposeViewControllerResultCancelled:
                output = @"Action Cancelled";
                break;
            case SLComposeViewControllerResultDone:
                output = @"Tweet Successful!";
                break;
            default:
                break;
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter" message:output delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [alert show];
    }];
}
有帮助吗?

解决方案

You should really consider reading the manual. The line itself is pretty self-explanatory:

[twitter setInitialText:[NSString stringWithFormat:@"***Say Something***"]];

Now, all you have to do is change it so that it's sourcing from your label. Assuming your label that you would like to tweet the text from is called factLabel, you'd have to do something like this:

[twitter setInitialText:factLabel.text];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top