Я пытаюсь загрузить изображения и текстовые файлы из основного пакета в поля UITextView и UIImageView. Я правильно подключил выходы из файла .xib и обеспечил, чтобы файлы, которые я пытаюсь загрузить, присутствуют в комплекте, но они не загружаются, и когда я тестирую их через NSLog, они возвращаются как null. Ниже приведен код из файлов .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