UITableViewController作为子视图获取错误

时间:2014-04-10 08:33:57

标签: ios uiviewcontroller uitableview subview

我有一个UIViewController,它作为子视图被加载到我的UIViewController上,但是我收到了这个错误

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

这是我的代码看起来像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];

}

2 个答案:

答案 0 :(得分:3)

viewcontroller没有frame属性,只有它的视图。

请改为尝试:

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

答案 1 :(得分:1)

@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.