我正在构建应用,但在尝试打开第二个视图时出现问题。
代码:
- (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;
}
输出:
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)
随时请求更多信息。我对目标c仍然相当新,所以我会尽我所能。
注意:我使用一个视图控制器文件(TextViewController.h TextViewController.m)用于两个视图(到目前为止我只有两个视图,但会有更多)因为所有视图看起来都相同但它们都共享相同码。每个视图都有一个“下一个按钮”和一个“文本框”
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.
}
答案 0 :(得分:1)
什么是Page1Text? (和Page2Text) 它是TextViewController的一个实例吗? (如果是这样..请..变量以小写字母开头) 并且..如果是这样..你的TextViewController类是否有属性名称字体?
@interface TextViewController : UIViewController
@property (nonatomic, strong) UIFont* font;
@end
答案 1 :(得分:1)