0
我有一個iOS項目,我在.xib頁面上有一列由文本組成的標籤,右側是其中的一個,是一組播放按鈕來播放每個音頻,比如在.M代碼:iOS:如何在Facebook上發佈標籤內容而不是靜態文本
-(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];
}
要播放按鈕的右邊,我有一個發佈到Facebook按鈕。我知道,我可以很容易地發佈靜態文本給Facebook像這樣:
-(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];
}
}
我想什麼做的,就是按下播放按鈕時,我想分配一個變量等於說是文本在關聯的標籤中。我想這應該很容易。然後,我想擺脫Play按鈕右側的單個Post到Facebook按鈕,並且我希望有一個應用欄按鈕,用於單個按鈕訪問以張貼到Facebook,標籤的內容將會是當一個人點擊播放按鈕時分配給變量。擁有一個Facebook按鈕意味着必須動態地將文本分配給發佈的變量。
有誰知道如何配置代碼來發布標籤或變量的內容而不是靜態文本?我已經尋找了一種方法來做到這一點,但沒有成功。
感謝Anoop!我會給它一個鏡頭!就我而言,如果我理解正確,我可能只需要myLabel.text。由於我在同一頁上有幾個標籤,我仍然需要弄清楚如何告訴我的(IBAction)pushButton將標籤分配給一個變量。 – user1362308
要弄清楚什麼? *將標籤分配給變量*?這裏有什麼大不了的? –
抱歉不清楚。我首先想到的是,我需要爲標籤分配一個名稱。我認爲這是在標籤本身突出顯示時在標識檢查器中完成的,位於標籤右側的文檔部分下方。假設我把「mylabelname」放在這個字段中。然後,我認爲必須將其添加到IBAction按鈕方法,可能是這樣的: posttofhotostext = mylabelname.text; - 然後,我可以在我的setInitialText中使用這樣的東西:NSString stringWithFormat:@「Posting to Facebook:%@」,posttofhotostext]]; - 我接近?謝謝! Rob – user1362308