我有一个初学者的问题。我想在我的代码的所有部分(而不是单个方法/函数)中访问 UIView。
因此我在@interface 部分声明了它
UIView *calendarView;
然后@property (nonatomic, retain) UIView *calendarView
。在@implementation 我有@synthesise calendarView
.
现在我想定义这个视图的框架并编码如下:
CGRect calendarFrame = CGRectMake(170, 8, 200, 50);
calendarView = [[UIView alloc] initWithFrame:calendarFrame];
但是我现在想知道我是否在这里做错了什么,因为 calendarView 已经被保留和综合了。UIView alloc 肯定是多余的,甚至必然会使应用程序崩溃,因为我遇到了内存问题,对吧?
所以我虽然我应该编码这个而不是前两行,但它只具有根本不显示 calendarView 的效果:
[calendarView setFrame:CGRectMake(170, 8, 200, 50)];
所以我的问题是我是否真的需要先分配视图才能使用它?还是有另一种解决方案?