I have rewritten this to try and make it more descriptive with more code hopefully:
I have set up a separate UIView
class called: pageTitleView code below:
header file:
#import <UIKit/UIKit.h>
@interface pageTitleView : UIView
@property (nonatomic, strong) IBOutlet UILabel *pageTitle;
@property (nonatomic, strong) IBOutlet UILabel *subTitle;
@end
The M File:
@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];
}
With in my parent view controller I have the following:
The Header File:
#import <UIKit/UIKit.h>
@interface UsingThisGuide : UIViewController
@property (strong, nonatomic) UIView *PageTitleBlock;
@property (strong, nonatomic) UIWebView *dispalyPageContent;
@property (strong, nonatomic) UIView *FooterBar;
@end
In the M file i have the following:
#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
No what i want to do is set the pageTitle.text
from the pageTitleView
class via its parent controller MyFirstView
using something like _PageTitleBlock.pageTitle.text=
but this is the error i am getting:
Property 'pageTitle' not found on object of type 'UIView *
The problem here, is that you are declaring your property called
PageTitleBlock
of typeUIView
inUsingThisGuide
, but then callpageTitle
which is declared in the classpageTitleView
. The compiler doesn't trust this.Change the type of
PageTitleBlock
fromUIView
topageTitleView
and you're good to go!