我试图在视图控制器中使用NSMutableDictionary,在点击图像时将图像和文本加载到详细视图控制器中。我是编程新手,我正在努力理解。有人可以帮忙。
以下是我在视图控制器1 .m
中的代码- (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasDoubleTapped:(int)index{
SomeDetailViewController *detailViewController = [[SomeDetailViewController alloc] initWithNibName:@"SomeDetailViewController" bundle:nil];
if ((int)index == 0) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"0002.jpg", @"imagekey",
@"This is #1", @"textkey", nil];
NSLog(@"%@", [myDictionary objectForKey:@"imagekey"]);
NSLog(@"%@", [myDictionary objectForKey:@"textkey"]);
}
[self.navigationController pushViewController:detailViewController animated:YES];
}
当我构建并运行它时,会调用图像键和文本键,但不会显示在详细视图控制器中。 我的detailViewController.h
#import <QuartzCore/QuartzCore.h>
@interface SomeDetailViewController : UIViewController < UITextViewDelegate, UINavigationControllerDelegate>{
IBOutlet UIImageView *imageView;
IBOutlet UITextView *myText;
NSString *imagekey;
NSMutableDictionary *myDictionary;
NSString *textkey;
}
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UITextView *myText;
@property (nonatomic, retain) NSString *imagekey;
@property (nonatomic, retain) NSString *textkey;
@property (nonatomic, retain) NSMutableDictionary *myDictionary;
@end
和我的detailViewContoller .m
@synthesize myDictionary;
- (void)viewDidLoad
{
[super viewDidLoad];
imageView .image = [[UIImage alloc] init];
self.imageView.image =[UIImage imageNamed:[(NSMutableDictionary *)myDictionary objectForKey:@"imagekey"]];
self.myText.text =[(NSMutableDictionary *)myDictionary objectForKey:@"textkey"];
}
我知道这与另一篇文章类似,但我建议不要使用NSUsersDefaults,所以我正在尝试这个。
没有错误但没有显示