我已经重写了它以尝试使用更多代码使其更具描述性:
我设置了一个单独的UIView
类,名为:pageTitleView 代码如下:头文件:
#import <UIKit/UIKit.h>
@interface pageTitleView : UIView
@property (nonatomic, strong) IBOutlet UILabel *pageTitle;
@property (nonatomic, strong) IBOutlet UILabel *subTitle;
@end
M 文件:
@implementation pageTitleView
@synthesize pageTitle;
@synthesize subTitle;
- (id)initWithFrame:(CGRect)frame{
pageTitle = [[UILabel alloc] initWithFrame:CGRectMake(0,labelPosY,300,20)];
pageTitle.textColor = txtColour;
pageTitle.backgroundColor = [UIColor clearColor];
pageTitle.textAlignment = NSTextAlignmentCenter;
pageTitle.font = [UIFont systemFontOfSize:14];
// pageTitle.text to be set by parent view
[self addSubview:pageTitle];
}
在我的父视图控制器中,我有以下内容:
头文件:
#import <UIKit/UIKit.h>
@interface UsingThisGuide : UIViewController
@property (strong, nonatomic) UIView *PageTitleBlock;
@property (strong, nonatomic) UIWebView *dispalyPageContent;
@property (strong, nonatomic) UIView *FooterBar;
@end
在 M 文件中,我有以下内容:
#import <QuartzCore/QuartzCore.h>
#import "pageTitleView.h"
#import "MyFirstView.h"
@interface MyFirstView ()
@end
@implementation MyFirstView {
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
_PageTitleBlock = [[pageTitleView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
_PageTitleBlock.layer.cornerRadius = 5;
_PageTitleBlock.pageTitle.text = @"This should work but not";
[self.view addSubview:_PageTitleBlock];
[super viewDidLoad];
}
@end
不,我想做的是通过其父控制器使用类似的东西pageTitle.text
从类中设置,但这是我得到的错误:pageTitleView
MyFirstView
_PageTitleBlock.pageTitle.text=
Property 'pageTitle' not found on object of type 'UIView *