これは「これには簡単な答えがあると確信している」という質問のもう1つですが、私は困惑しています。
テンプレートの分割ビューコントローラを使用しています。NSStringを_detailItem変数に正常に渡しましたが、それを使用して画像を作成し、UIImageView(「stripImage」という名前)にロードすることができません。
[self.stripImage setImage:[UIImage imageNamed:_detailItem]];まで機能し ます。
文字列リテラルを同じコード行(@ "image20.jpg"など)に入れると、正常に機能します。
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
NSLog(@"_detailItem is still: %@",_detailItem);
// correctly reports the name of the imagefile (for example: "image20.jpg"
[self.stripImage setImage:[UIImage imageNamed: _detailItem]];
NSLog(@"The image being shown is: %@",self.stripImage.image);
//returns "The image being shown is: (null)"
}
}
頭が爆発しないように助けてください。前もって感謝します。
...そして私はそれをこのように試しました:
(私のマスタービューコントローラーで):
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Selected row %i",[indexPath row]);
NSString *imageName = [[stories objectAtIndex:[indexPath row]] objectForKey:@"link"];
NSLog(@"The image is: %@", imageName);
// These two work, oddly enough...
self.detailViewController.detailTitle.text = [[stories objectAtIndex:[indexPath row]]
objectForKey:@"title"];
self.detailViewController.detailSubtitle.text = [[stories objectAtIndex:[indexPath row]]
objectForKey:@"subtitle"];
// this one, not so much...
[self.detailViewController loadUpImageWith:imageName];
}
と私の詳細ビューコントローラーで:
- (void)loadUpImageWith:(NSString *)what
{
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString
stringWithFormat:@"strips/%@", what]];
NSLog(@"The file's url is: %@",path);
UIImage *img = [UIImage imageWithContentsOfFile:path];
NSLog(@"The resultant image is: %@",img);
stripImage.image = img;
}
しかし、ここに奇妙なことがあります...変数(この場合は「what」)を文字列リテラルに置き換えると、次のようになります。
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString
stringWithFormat:@"strips/%@", @"grumbles300.jpg"]];
...それは機能し、その1つの画像を表示します。でもそこで変数が使えるようになりたい!!
オビワンケノービを助けて!あなたは私の唯一の希望です。