Iphone 问题子类化UIView
我创建了自己的自定义视图,具有自己的头文件、主文件和相应的nib(.xib): 头文件Iphone 问题子类化UIView,iphone,uiview,Iphone,Uiview,我创建了自己的自定义视图,具有自己的头文件、主文件和相应的nib(.xib): 头文件 #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface PointsBarView : UIView { IBOutlet UIView *pointsBarView; IBOutlet UIView *pointsCounterView; IBOutlet UILabel
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface PointsBarView : UIView
{
IBOutlet UIView *pointsBarView;
IBOutlet UIView *pointsCounterView;
IBOutlet UILabel *pointsTotalLabel;
UIImageView *handImageView;
UIImageView *powerBarOutlineImageView;
}
@property (nonatomic, retain) IBOutlet UIView *pointsCounterView;
@property (nonatomic, retain) IBOutlet UIView *pointsBarView;
@property (nonatomic, retain) IBOutlet UILabel *pointsTotalLabel;
@property (nonatomic, retain) IBOutlet UIImageView *handImageView;
@property (nonatomic, retain) IBOutlet UIImageView *powerBarOutlineImageView;
@end
并且我添加如下内容:
@property (nonatomic, assign) IBOutlet PointsBarView *pointsBarView;
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"PointsBarView" owner:self options:nil];
pointsBarView = [nibViews objectAtIndex: 0];
[[self view] addSubview:pointsBarView];
如何访问NIB中的这些子视图?它们是否需要嵌入到pointsBarView
中?(pointsBarView
引用NIB的主视图,所有其他视图都在pointsBarView
中)。它们是否应该是NIB的一个单独部分,我需要调用addSubview
来显示它们
我应该注意,如果我没有连接
PointsBarView
中的任何属性,则视图与我的UIViewController
类中的代码显示得很好。但我希望能够与每个视图交互并相应地更改属性。任何帮助都会很好 一般的经验法则是:如果从代码中加载,则在代码中连接它
相反地:
如果在IB中实例化,则可以连接IB中的出口和操作
在这里,您正在代码中加载视图,因此必须手动连接它们
如果您希望能够连接IB中的内容,请在IB中添加UIVIew,并将子类更改为PointsBarView。IB将神奇地读取PointsBarView.h文件,您应该能够连接插座、目标和操作