我一直在尝试从主包加载图像和文本文件到UITextView和UIImageView框中。我已经从.xib文件中正确地连接了插座,并确保我尝试加载的文件存在于软件包中,但它们没有加载,并且当我通过NSLog测试它们时,它们返回为空。下面复制的是.h和.m文件中的代码。如果你想知道,一些网点是强大的,因为我一直在试图搞乱设置才能使其运行起来,至今无济于事。无法以编程方式将文件从捆绑包加载到UITextView和UIImageView
“.h文件中”
@interface CluesViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *cluesBackground;
@property (weak, nonatomic) IBOutlet UIImageView *titleImage;
@property (weak, nonatomic) IBOutlet UIImageView *typeATitle;
@property (weak, nonatomic) IBOutlet UIImageView *typeBTitle;
@property (weak, nonatomic) IBOutlet UIImageView *divider;
@property (weak, nonatomic) IBOutlet UITextView *typeAText;
@property (strong, nonatomic) IBOutlet UITextView *typeBText;
-(void)updateCluesViewInfoTypeA:(NSString *)typeA updateCluesViewInfoTypeB:(NSString *)typeB;
@end
“.m文件”
-(void)updateCluesViewInfoTypeA:(NSString *)typeA updateCluesViewInfoTypeB:(NSString *)typeB {
NSString *bGImageString = NULL;
bGImageString = [NSString stringWithFormat:@"%@&%@-bg", typeA, typeB];
NSString *bGPath = [[NSBundle mainBundle] pathForResource:bGImageString ofType:@"png"];
UIImage *bGImage = [UIImage imageNamed:bGPath];
[_cluesBackground setImage:bGImage];
NSString *titleImageString = NULL;
titleImageString = [NSString stringWithFormat:@"%@&%@-clues", typeA, typeB];
NSString *titleImagePath = [[NSBundle mainBundle] pathForResource:titleImageString ofType:@"png"];
UIImage *titleImage = [UIImage imageNamed:titleImagePath];
[_titleImage setImage:titleImage];
NSString *typeATitleImageString = NULL;
typeATitleImageString = [NSString stringWithFormat:@"%@-text", typeA];
NSString *typeATitlePath = [[NSBundle mainBundle] pathForResource:typeATitleImageString ofType:@"png"];
UIImage *typeATitleImage = [UIImage imageNamed:typeATitlePath];
[_typeATitle setImage:typeATitleImage];
NSString *typeBTitleImageString = NULL;
typeBTitleImageString = [NSString stringWithFormat:@"%@-text", typeB];
NSString *typeBTitlePath = [[NSBundle mainBundle] pathForResource:typeBTitleImageString ofType:@"png"];
UIImage *typeBTitleImage = [UIImage imageNamed:typeBTitlePath];
[_typeBTitle setImage:typeBTitleImage];
NSString *dividerImageString = NULL;
dividerImageString = [NSString stringWithFormat:@"%@&%@-divider", typeA, typeB];
NSString *dividerImagePath = [[NSBundle mainBundle] pathForResource:dividerImageString ofType:@"png"];
UIImage *dividerImage = [UIImage imageNamed:dividerImagePath];
[_divider setImage:dividerImage];
NSString *typeATextString = NULL;
typeATextString = [NSString stringWithFormat:@"%@Clues", typeA];
NSString *typeATextPath = [[NSBundle mainBundle] pathForResource:typeATextString ofType:@"txt"];
NSString* typeATextContent = [NSString stringWithContentsOfFile:typeATextPath encoding:NSASCIIStringEncoding error:NULL];
self.typeAText.text = typeATextContent;
NSString *typeBTextString = NULL;
typeBTextString = [NSString stringWithFormat:@"%@Clues", typeB];
NSString *typeBTextPath = [[NSBundle mainBundle] pathForResource:typeBTextString ofType:@"txt"];
NSString* typeBTextContent = [NSString stringWithContentsOfFile:typeBTextPath encoding:NSASCIIStringEncoding error:NULL];
self.typeBText.text = typeBTextContent;
NSLog(@"The textfield is %@", self.typeBText.text);
}
什么时候调用'updateCluesViewInfoTypeA:updateCluesViewInfoTypeB:'?它必须在调用'viewDidLoad'后调用。 – rmaddy
它在viewDidLoad之后调用。 – NBAfan