Question

I have a UIViewController which is being loaded onto my UIViewController as a subview, however I am getting this error

Property 'frame' not found on object of type 'mynamedTableViewController *'

This is what my code looks like for the UIViewController. .h

#import <UIKit/UIKit.h>
#import "FilterButtonsTableViewController.h"

@interface MainFilterViewController : UIViewController


@property (strong, nonatomic) UIButton *applyButton;
@property (strong, nonatomic) UIButton *cancelButton;
@property (strong, nonatomic) UIButton *clearAllButton;

@property (strong, nonatomic) FilterButtonsTableViewController *filterButtonsTableViewController;

@end

.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

// add header label
    UILabel *noteHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(25.0, 0.0, 200.0, 45.0)];
    noteHeaderLabel.backgroundColor = [UIColor clearColor];
    noteHeaderLabel.textColor = [UIColor lightGrayColor];
    // dynamic using whatViewName
    noteHeaderLabel.text = @"Filter";
    [self.view addSubview:noteHeaderLabel];

// add underlines
    // top
    UIView *topUnderline = [[UIView alloc] initWithFrame:CGRectMake(0.0, 45.0, self.view.frame.size.width, 1.0)];
    topUnderline.backgroundColor = [UIColor lightGrayColor];
    topUnderline.alpha = 0.8;
    // bottom
    UIView *bottomUnderline = [[UIView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-45.0, self.view.frame.size.width, 1.0)];
    bottomUnderline.backgroundColor = [UIColor lightGrayColor];
    bottomUnderline.alpha = 0.8;
    // addviews
    [self.view addSubview:topUnderline];
    [self.view addSubview:bottomUnderline];

// add buttons to view
    // apply
    applyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    applyButton.userInteractionEnabled = YES;
    [applyButton addTarget:self action:@selector(alertViewSelected:) forControlEvents:UIControlEventTouchDown];
    [applyButton setTitle:@"Save" forState:UIControlStateNormal];
    applyButton.frame = CGRectMake(self.view.frame.size.width - 130, self.view.frame.size.height - 43, 120.0, 40.0);
    [self.view addSubview:applyButton];

    // cancel
    cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    cancelButton.userInteractionEnabled = YES;
    [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [cancelButton  addTarget:self action:@selector(alertViewSelected:) forControlEvents:UIControlEventTouchUpInside];
    [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
    cancelButton.frame = CGRectMake(self.view.frame.size.width - 260, self.view.frame.size.height - 43, 120.0, 40.0);
    [self.view addSubview:cancelButton];

    // cancel
    clearAllButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    clearAllButton.userInteractionEnabled = YES;
    [clearAllButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [clearAllButton addTarget:self action:@selector(alertViewSelected:) forControlEvents:UIControlEventTouchUpInside];
    [clearAllButton setTitle:@"Clear filter" forState:UIControlStateNormal];
    clearAllButton.frame = CGRectMake(0.0, self.view.frame.size.height - 43, 120.0, 40.0);
    [self.view addSubview:clearAllButton];

//TavleView
    filterButtonsTableViewController = [[[FilterButtonsTableViewController alloc] init];
    filterButtonsTableViewController.frame:CGRectMake(5.0, 65.0, (self.view.frame.size.width/2)-10, 235.0);
    [self.view addSubview:filterButtonsTableViewController.view];

}
Was it helpful?

Solution

A viewcontroller does not have a frame property, only its view does.

Try this instead :

filterButtonsTableViewController.view.frame = CGRectMake(5.0, 65.0, (self.view.frame.size.width/2)-10, 235.0);

OTHER TIPS

@interface MainFilterViewController : UIViewController

filterButtonsTableViewController = [[FilterButtonsTableViewController alloc] init];
[self.view addSubview:filterButtonsTableViewController.view];

//  this code helps you to add tableview controller as a sub view.

@interface FilterButtonsTableViewController

 self.view.frame=CGRectMake(0, 50, 150, 150);

// frame of the tableviewController is set on his class.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top