【发布时间】:2015-06-22 12:23:38
【问题描述】:
- 在情节提要中,我将 UIView 拖到了 ViewController 上。
- 将 UIView 分配给自定义类“myUIView”(即 myUIView.h 和 myUIView.m)
- 像这样设置 ViewController:
ViewController.h
#import <UIKit/UIKit.h>
@interface ScheduleViewingVC : UIViewController
//for the dragged-out UIView
@property (strong, nonatomic) IBOutlet UIView *myUIViewOutlet;
//to do some drawings on myUIViewOutlet
@property (strong, nonatomic) myUIView *myUIViewClass;
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//resize my UIView into a square
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGRect squareFrame = CGRectMake(0, 0, screenWidth, screenWidth);
_myUIViewOutlet = [[UIView alloc] initWithFrame:squareFrame];
}
@end
如果我运行这个项目,
- (void)drawRect:(CGRect)rect {}
在 myUIViewClass.m 内自动运行,因为它链接到 myUIViewOutlet。
现在,我需要从 ViewController 将一些数据发送到链接到 myUIViewOutlet 的 myUIViewClass。
从 ViewController 向 myUIViewOutlet 发送数据似乎不正确。 我怎样才能使它正常工作?我应该向 myUIViewClass 发送数据吗?
谁能帮我说清楚?谢谢!
【问题讨论】:
-
链接到 myUIViewOutlet 的 myUIViewClass 是什么意思?你认为它们是对象吗?
-
UIView(小框架)不应该有自己的类来对自己做一些方法吗?
标签: ios objective-c iphone uiview uiviewcontroller