无法从Controller设置UIView背景颜色

时间:2013-08-25 17:44:07

标签: objective-c ios6 uiview xcode4.6

我有一个应用程序(XCode 4.6,Storyboards,iOS 6.2和ARC),有几个UIViews:

enter image description here

每个UIView都具有在XCode中定义的背景颜色。我希望能够根据用户选择的方案更改背景颜色(当前为lightYellow)。在CalendarViewController的 -viewDidLoad 方法中,我有以下代码:

self.leftGrid.backgroundColor = [UIColor blueColor];
[self.leftGrid setNeedsDisplay];

这是CalendarViewController的.h文件中的代码:

//  these all all UIViews
@class SubViewGrid;
@class SubViewData;
@class CalendarView;
@class TopGrid;
@class LeftGrid;

@interface CalendarViewController : UIViewController <UIScrollViewDelegate>  {

}

//  UIScrollView properties
@property (nonatomic, weak) IBOutlet UIScrollView *schedScrollView;
@property (strong, nonatomic) IBOutlet UIView *topGrid;
@property (strong, nonatomic) IBOutlet UIView *leftGrid;
@property (strong, nonatomic) IBOutlet UIScrollView *topGridSV;
@property (strong, nonatomic) IBOutlet UIScrollView *leftGridSV;

问题是:没有任何反应!我究竟做错了什么? (我看过SO和谷歌搜索,但没有发现任何相关内容)

1 个答案:

答案 0 :(得分:1)

self.leftGrid == nil中似乎是viewDidLoad。也许xib的所有者设置不正确。或者IB中的视图与其所有者字段之间的连接。