0

I have an iOS project, where I have on a .xib page, a column of Labels consisting of text, and to the right of which, are a set of play buttons to play each audio, such as in the .m code:

-(IBAction)pushButton {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"mysound" ofType:@"mp3"];
    if(theAudio)[theAudio release];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    theAudio.volume = 1.0;
    [theAudio play];
}

To the right of the play button, I have a Post to Facebook button. I know that I can easily post static text to Facebook like so:

-(IBAction)ShareFB1 {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    slComposeViewController = [[SLComposeViewController alloc] init];
    slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [slComposeViewController setInitialText:@"My static text that has the contents of the label manually entered"];
    [slComposeViewController addURL:[NSURL URLWithString:@"http://stackoverflow.com"]];
    [self presentViewController:slComposeViewController animated:YES completion:NULL];
}
else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Facebook Account" message:@"There are no Facebook accounts confiured, configure or create accounts in Settings." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alert show];
    [alert release];
}
}

What I would like to do, is when the play button is pressed, I want to assign a variable to be equal to the text that is in the associated label. I imagine that should be easy enough. Then, I want to get rid of the individual Post to Facebook buttons to the right of the Play buttons, and I want to have an app bar button for single button access to post to Facebook, with the contents of the label, which would be assigned to the variable when one hits the play button. Having one Facebook button means having to dynamically assign the text to the variable be posted.

Does anyone know how to configure the code to post the contents of a label, or a variable, rather than static text? I have searched for a way to do this, but have not been successful.

4

1 回答 1

1

What about using:

[slComposeViewController setInitialText:[NSString stringWithFormat:@"Your text no.%d here: %@",yourCounter, yourLabel.text]];

EDIT:

NSString  *posttofacebooktext=[mylabelname text];
[slComposeViewController setInitialText:[NSString stringWithFormat:@"Posting to Facebook: %@", posttofacebooktext]];
于 2013-03-30T16:46:24.280 回答