Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to programmatically load files from bundle to UITextView and UIImageView
    primarykey
    data
    text
    <p>I've been trying to load images and text files from the main bundle into UITextView and UIImageView boxes. I have connected the outlets properly from the .xib file and have ensured the files I am trying to load are present in the bundle, but they are not loading, and when I test them through NSLog they come back as null. Copied below is code from the .h and .m files. In case you were wondering, some of the outlets are strong, because I've just been trying to mess with the settings to get it to work, so far to no avail.</p> <p>".h file"</p> <pre><code>@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 </code></pre> <p>".m file"</p> <pre><code>-(void)updateCluesViewInfoTypeA:(NSString *)typeA updateCluesViewInfoTypeB:(NSString *)typeB { NSString *bGImageString = NULL; bGImageString = [NSString stringWithFormat:@"%@&amp;%@-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:@"%@&amp;%@-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:@"%@&amp;%@-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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload