0

I'm building an app but having a problem when i try and open a second view.

The code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSInteger FontSizeValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
    UIFont *pagedefault = [UIFont fontWithName:@"Arial" size:FontSizeValue];
    Page1Text.font = pagedefault;
    Page2Text.font = pagedefault;
}

Output:

2012-03-16 11:16:11.573 Accessibility Guide[3418:f803] *** Terminating app due to  
uncaught exception 'NSUnknownKeyException', reason: '[<TextViewController 0x687e4d0> 
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 
Page2.'
*** First throw call stack:
(0x13cd022 0x155ecd6 0x13ccee1 0x9c5022 0x936f6b 0x936edb 0x951d50 0x23971a 0x13cedea 
0x13387f1 0x23826e 0xde1fc 0xde779 0xde99b 0xded11 0xf08fd 0xf0aef 0xf0dbb 0xf185f 
0xf1e06 0xf1a24 0x44dde6 0x4424d0 0xa8581 0xa87fa 0x93d85d 0x13a1936 0x13a13d7 0x1304790 
0x1303d84 0x1303c9b 0x12b67d8 0x12b688a 0x17626 0x233d 0x22a5)
terminate called throwing an exception(lldb) 

Feel free to request any more information. I'm still fairly new to objective-c so I'll do my best.

NOTE: I am using one view controller file (TextViewController.h TextViewController.m) for two views (i only have two views so far but there will be more) because all the views look the same but they all share the same code. Each view has a "Next Button" and a "Text Box"

TextViewController.h

#import <UIKit/UIKit.h>

@interface TextViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *Page1Text;
@property (weak, nonatomic) IBOutlet UITextView *Page2Text;

@end

TextViewController.m

#import "TextViewController.h"

@interface TextViewController ()

@end

@implementation TextViewController
@synthesize Page1Text;
@synthesize Page2Text;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSInteger FontSizeValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
    UIFont *pagedefault = [UIFont fontWithName:@"Arial" size:FontSizeValue];
    Page1Text.font = pagedefault;
    Page2Text.font = pagedefault;
}
- (void)viewDidUnload
{
    [self setPage1Text:nil];
    [self setPage2Text:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}
ReArmedHalo
  • 35
  • 1
  • 1
  • 6

2 Answers2

1

What is Page1Text? (and Page2Text) Is it an instance of your TextViewController? (if so.. please.. variables starts with lower case letter) And.. if it is so.. Does your TextViewController class has a property names font?

 @interface TextViewController : UIViewController
 @property (nonatomic, strong) UIFont* font;
 @end
Francesco
  • 1,840
  • 19
  • 24
  • Page1Text and Page2Text are text fields on the views. I believe that answers your other question also. I keep forgetting the proper way to declare names with capitals and lowercase. sorry – ReArmedHalo Mar 16 '12 at 15:37
  • can you post the interface of your class (where the properties are declared)? Have you tried to access the properties through self? (self.Page1Text.font = pagedefault) – Francesco Mar 16 '12 at 15:46
  • Sure, I'll add it to the main question. – ReArmedHalo Mar 16 '12 at 15:46
  • so.. try calling the getter instead of accessing directly the variable (self.Page1Text.font = pagedefault) – Francesco Mar 16 '12 at 15:53
  • 1
    I've figured out my problem! When i control clicked and dragged a connection to the assisted editor (I love that!) I accidentally called it "Page2" instead of "Page2Text". When I saw the error in the code I changed it everywhere in the code... but I didn't drag a new connection down from interface builder. Sometimes it's the littlest thing that makes the difference! :D Thanks for all the help anyways! It lead me to this discovery! I'm not sure who I'm going to give the points to yet. – ReArmedHalo Mar 16 '12 at 15:59
1

This seems to happen when some component, like a XIB file, expects your class to have an accessor for a key that it can't find. Are you binding something to Page2?

Similar questions here and here.

Community
  • 1
  • 1
CJ Foley
  • 101
  • 4