我在編碼方面仍然很新穎,並且試圖結合來自兩個項目的示例代碼。NSString從for循環傳遞變量。
問:
基本上,我想捕捉到的圖像文件(全名爲card1.gif,card2.gif等)for循環的名稱,並將其設置爲_imagename變量,所以我可以將文件名稱傳遞給Facebook代碼以將該圖像與帖子一起包含。不太確定如何將FB代碼與圖像顯示循環代碼結合起來。
感謝您的任何幫助!
CGRect newViewSize = Scroller.bounds;
int NumberOfImages = 20;
int i;
for(i=0;i<NumberOfImages;i++){
if(i == 0){
//Setup first picture
UIImageView *ImgView = [[UIImageView alloc] initWithFrame:newViewSize];
NSString *FilePath = [NSString stringWithFormat:@"Page_%d.png", i];
[ImgView setImage:[UIImage imageNamed:FilePath]];
[Scroller addSubview:ImgView];
}else{
//Setup the rest of the pictures
newViewSize = CGRectOffset(ViewSize, Scroller.bounds.size.width, 0);
UIImageView *ImgView = [[UIImageView alloc] initWithFrame:newViewSize];
NSString *FilePath = [NSString stringWithFormat:@"Page_%d.png", i];
[ImgView setImage:[UIImage imageNamed:FilePath]];
[Scroller addSubview:ImgView];
}
}
[self.view addSubview:Scroller];
}
- (IBAction)facebook:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:@"Insert FB text here"];
[controller addURL:[NSURL URLWithString:@"http://www.cnn.com"]];
[controller addImage:[UIImage imageNamed:_imagename]];
[self presentViewController:controller animated:YES completion:Nil];
}
}
每當循環結束時,你想要在Facebook上發佈該特定圖像?或者你想要一組圖像,以便以後使用它們? –
每次循環結束時,我都需要該特定圖像名稱,以便插入我的FB代碼,並且僅在用戶單擊FB圖標以共享該圖像時才使用。我一直在玩與陣列沒有運氣,但修改此代碼。 – user3534305