【发布时间】:2014-01-28 21:20:53
【问题描述】:
我有一个故事板驱动的 iOS 应用程序。 我的目标是将一个小方形视图(定义为其他 XIB)添加到主 ViewController 上的另一个 UIView。 *// 请注意,我已正确分配 Identity Inspector 中的类名*
在主ViewController上,我手动添加了一个UIView(myHolderView),并在ViewController界面中添加了一个UIView成员。
//.h
@interface ViewController : UIViewController
@property(nonatomic, strong) IBOutlet UIView *myHolderView;
@end
而且,我已经通过“BlueString”连接了这个 IBOutlet :)
现在,我添加了另一个具有单一视图的 XIB - 将其命名为 MySquare.xib 并在其上添加了一个标签。 并且,添加了一个带有 .h 和 .m 文件的 UIView 类。并且,建立了“BlueString”连接。
@interface MySquare : UIView
@property(nonatomic, strong) IBOutlet UILabel *myLabel;
@end
现在,在实现中:
@implementation ViewController
@synthesize myHolderView;
- (void)viewDidLoad
{
[super viewDidLoad];
MySquare *sq=[[MySqure alloc]init];
// Do any additional setup after loading the view, typically from a nib.
[self.myHolderView addSubview:sq];
}
当我在模拟器中运行它时,它只显示主视图,但方形视图没有出现。 我知道主视图已加载,因为...我更改了它的颜色以便我可以看到。 请帮忙。
【问题讨论】:
-
嗨!你有没有成功解决这个问题?