从 xib/nib 加载视图时的奇怪行为

发布于 2024-10-17 02:57:56 字数 1658 浏览 1 评论 0原文

从 xib/nib 加载视图时,我的应用程序出现奇怪的行为。 我无法再从代码中访问我与界面生成器连接的控件 - 意味着我无法替换它们或更改文本和排序。 (尽管控件仍然会触发 IBActions.. 就像按钮单击一样) 我在使用 uisearchbar 时已经遇到了这个问题。但广泛删除并再次添加它并在 Interface Builder 中重新连接它以某种方式解决了这个问题。 ​​iPad/iPhone uiSearchbar 透明背景

我想避免对这里的每个血腥控件都这样做xib 所以我试图把它确定下来。我发现一旦我从 xib 加载视图,奇怪的行为就会开始。 (虽然已经工作的控件,如 uisearchbar,继续工作)

我所做的就是加载几个视图(来自同一个 xib,视图控制器是所有者)以将它们放入滚动视图中。这很好用..

这是代码:

UIView *viewContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2304, 575)];
NSArray *nibViews1 = [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad" owner:self options:nil];
PrescriptionView *view1 = [nibViews1 objectAtIndex:1];
NSArray *nibViews2 = [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad" owner:self options:nil];
PrescriptionView *view2 = [nibViews2 objectAtIndex:1];
NSArray *nibViews3 = [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad" owner:self options:nil];
PrescriptionView *view3 = [nibViews3 objectAtIndex:1];
NSMutableArray *arrayViews = [[NSMutableArray alloc] init];
[arrayViews addObject:view1];
[arrayViews addObject:view2];
[arrayViews addObject:view3];
int intX = 1;
int intY = 1; 
for (UIView *viewImage in arrayViews)
{
    [viewImage setFrame:CGRectMake(intX, intY, 768, 575)];
    [viewContainer addSubview:viewImage];
    intX = intX + 768;
}

[arrayViews release];
[prescriptionScrollView setContentSize:CGSizeMake(2304, 575)];
[prescriptionScrollView addSubview:viewContainer];
[viewContainer release];

安迪的想法?建议?这是一个错误吗?

非常感谢。

此致 时间

I am experiencing a weird behaviour of my app when loading views from a xib/nib.
I cant access my controls I hooked up with interface builder from code any more-- means I cant replace them or change text and sorts. (the controls will still fire IBActions though.. like button-clicks)
I had this problem already with a uisearchbar. but extensively deleting and adding it again and reconnceting it in Interface Builder somehow solved the issue.
iPad/iPhone uiSearchbar transparent background

I want to avoid doing this with every bloody control in this xib so I tried to nail it down. I found out that as soon as I load a view from my xib, the weird behaviour starts. (though the controls which are already working, as the uisearchbar, keep working)

what I do, is to load a couple of Views(from the same xib the viewcontroller is the owner) to place them into a scrollview. this works nicely..

here is the code:

UIView *viewContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2304, 575)];
NSArray *nibViews1 = [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad" owner:self options:nil];
PrescriptionView *view1 = [nibViews1 objectAtIndex:1];
NSArray *nibViews2 = [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad" owner:self options:nil];
PrescriptionView *view2 = [nibViews2 objectAtIndex:1];
NSArray *nibViews3 = [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad" owner:self options:nil];
PrescriptionView *view3 = [nibViews3 objectAtIndex:1];
NSMutableArray *arrayViews = [[NSMutableArray alloc] init];
[arrayViews addObject:view1];
[arrayViews addObject:view2];
[arrayViews addObject:view3];
int intX = 1;
int intY = 1; 
for (UIView *viewImage in arrayViews)
{
    [viewImage setFrame:CGRectMake(intX, intY, 768, 575)];
    [viewContainer addSubview:viewImage];
    intX = intX + 768;
}

[arrayViews release];
[prescriptionScrollView setContentSize:CGSizeMake(2304, 575)];
[prescriptionScrollView addSubview:viewContainer];
[viewContainer release];

andy ideas? suggestions? is this a bug?

Thank you very much.

Best regards
T

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你不是我要的菜∠ 2024-10-24 02:57:56

作为对此的更新,我很确定这是一个错误。
将视图放入自己的 nib 文件中,而不是从同一个 xib 中加载视图,有助于消除这种奇怪的行为。
无论如何,我向苹果提出了支持票,但在出于一些愚蠢的原因两次拒绝我的票后,我厌倦了尝试。
感谢所有花时间阅读本文的人。
干杯!

As an update for this, I am pretty sure this is a bug.
Placing the view into its own nibfile instead of loading the view from within the same xib helped getting rid of this weird behaviour.
Anyway, I raised a support ticket with apple, but after rejecting my ticket twice for some dumb reasons, I got tired of trying.
thanks to anyone who took the time reading this.
cheers!

辞取 2024-10-24 02:57:56

您如何定义您的销售点?它们应该这样定义:

@property (nonatomic, retain) IBOutlet MyView *myViewOutlet;

另请注意,出口应该在 viewDidUnload 和 dealloc 中释放和清空。

How are you defining your outlets? They should be defined like this:

@property (nonatomic, retain) IBOutlet MyView *myViewOutlet;

Also note the outlets should be released and nilled in viewDidUnload and dealloc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文