加载/重新加载 xib uiview
Posted
技术标签:
【中文标题】加载/重新加载 xib uiview【英文标题】:load/reload xib uiview 【发布时间】:2013-01-12 15:34:42 【问题描述】:我正在尝试使用以下代码为自定义键盘加载 xib 文件。之后,我需要卸载然后重新加载。我不明白如何重新加载此代码。我想知道怎么做。
- (id)init
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
CGRect frame;
if(UIDeviceOrientationIsLandscape(orientation))
frame = CGRectMake(0, 0, 480, 162);
else
frame = CGRectMake(0, 0, 320, 216);
self = [super initWithFrame:frame];
if (self)
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PMCustomKeyboard" owner:self options:nil];
[[nib objectAtIndex:0] setFrame:frame];
self = [nib objectAtIndex:0];
[[NSBundle mainBundle] loadNibNamed:@"KeyBoardAccView_iPhone" owner:self options:nil];
[self.altButton setTitle:kAltLabel forState:UIControlStateNormal];
[self.returnButton setTitle:kReturnLabel forState:UIControlStateNormal];
self.returnButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[self loadCharactersWithArray:kChar];
[self.spaceButton setBackgroundImage:[PMCustomKeyboard imageFromColor:[UIColor colorWithWhite:0.5 alpha:0.5]]
forState:UIControlStateHighlighted];
self.spaceButton.layer.cornerRadius = 7.0;
self.spaceButton.layer.masksToBounds = YES;
self.spaceButton.layer.borderWidth = 0;
[self.spaceButton setTitle:kSpaceLabel forState:UIControlStateNormal];
return self;
-(void)setTextView:(id<UITextInput>)textView
if ([textView isKindOfClass:[UITextView class]])
[(UITextView *)textView setInputView:self];
else if ([textView isKindOfClass:[UITextField class]])
[(UITextField *)textView setInputView:self];
_textView = textView;
NSLog(@"setTextView");
-(id<UITextInput>)textView
return _textView;
【问题讨论】:
【参考方案1】:我刚刚发布了一个关于如何从 .xib 文件加载自定义 UIView 的示例项目。
https://github.com/PaulSolt/CompositeXib
您将需要一个额外的 UIView 插座和此代码用于名为 WidgetView 的类/.xib 文件:
- (id)initWithCoder:(NSCoder *)aDecoder
self = [super initWithCoder:aDecoder];
if(self)
[self setup];
return self;
- (void)setup
[[NSBundle mainBundle] loadNibNamed:@"WidgetView" owner:self options:nil];
[self addSubview:self.view];
【讨论】:
以上是关于加载/重新加载 xib uiview的主要内容,如果未能解决你的问题,请参考以下文章
从 iOS 中的 UIView 子视图重新加载时 UITableView 未重新加载