我遇到的问题似乎没有明显的解决方案。我进行了搜索,找到了所有常见的答案。
启动时,我的自定义Xib视图未显示在应用程序上。背景清晰,此xib具有5个图像视图,如下图所示,这些视图未设置为隐藏。
该类也有大约5个委托,我在初始化委托时从调用者设置它。 initWithDelegates:
的调用者是显示此xib的父UIViewController。
CustomView.h
@interface CustomView : UIView<SomeProtocol>
// UI Items - THESE AREN'T SHOWING UP
@property (strong, nonatomic) IBOutlet UIImageView *image1;
@property (strong, nonatomic) IBOutlet UIImageView *image2;
@property (strong, nonatomic) IBOutlet UIImageView *image3;
@property (strong, nonatomic) IBOutlet UIImageView *image4;
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIStackView *centerStackView;
- (id)initWithDelegates:(UIViewController*)delegate1 withDelegate2:(NSObject<Delegate2>*)delegate2 withDelegate3:(NSObject<Delegate3>*)delegate3 withDelegate4:(UIViewController<Delegate4>*)delegate4
withDelegate5:(NSObject<Delegate5>*)delegate5;
@end
CustomView.m
@implementation CustomView
- (void)awakeFromNib {
[super awakeFromNib];
}
- (id)initWithDelegates:(UIViewController*)delegate1 withDelegate2:(NSObject<Delegate2>*)delegate2 withDelegate3:(NSObject<Delegate3>*)delegate3 withDelegate4:(UIViewController<Delegate4>*)delegate4
withDelegate5:(NSObject<Delegate5>*)delegate5
{
NSArray * arr =[[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil];
self = [arr firstObject];
self.delegate1 = delegate1;
self.delegate2 = delegate2;
self.delegate3 = delegate3;
self.delegate4 = delegate4;
self.delegate5 = delegate5;
[self setLoopImage];
[self layoutIfNeeded];
return self;
}
@end
我还验证了什么:
感谢您的帮助!
更新:
我相信这与将笔尖放在嵌套的UIView中有关。在界面构建器中,顺序为UIViewController-> UIView-> nibs
似乎没有像UITableView这样的类中从父UIViewController注册笔尖的方法。
我也尝试过:
(id)initWithDelegates
方法不进行初始化或在复制对象的情况下注册nib。我通过删除1)return self
,2)注册笔尖的行和3)使方法原型返回空值的方法来完成此操作-即(void)initWithDelegates
-这也不起作用。 [self addSubview: self.image1];
[self bringSubviewToFront: self.image1];
[self.menuImage setHidden:image1];
-没有运气。 答案 0 :(得分:0)
在自定义XIB中检查您的自动版式。因此,包含项未显示。例如:仅垂直居中和水平居中。尝试在自定义类的视图中执行不同的自动布局约束。
答案 1 :(得分:0)
我认为CustomView在ParentView中的布局有些问题。您能不能?
在将CustomView的框架添加到ParentView中时对其进行检查。
检查在ParentView内部具有CustomView的约束。如果你不这样做 有它们-添加它,约束将使iOS胶水如何布局您的 CustomView。有关更多信息,请点击Programmatically Creating Constraints
答案 2 :(得分:0)
笔尖不能嵌套在结构中。
代替:
UIViewController -> UIView -> 笔尖..
应该是:
UIViewController -> Container View -> UIView with nibs.