从 UIView 更改为另一个类中的 UIView

发布于 2025-01-03 13:26:39 字数 1338 浏览 4 评论 0原文

这是我遇到的一个小问题。我不太擅长以编程方式更改视图,但这就是我所拥有的:

//(.h)


#import <UIKit/UIKit.h>
#import "Detail.h"

@interface List : UIViewController <UITableViewDelegate, UITableViewDataSource>
{

}

@property (retain, nonatomic) IBOutlet UITableView *tableView;
@property (retain, nonatomic) Detail *detail;
@end

作为

//(.m)
@synthesize detail=_detail;

- (Detail *)detail
{
    NSLog(@"Detail UIView construction started.");
    if (_detail != nil)
    {
        return _detail;
    }

    Detail *aDetailView = [[Detail alloc] init];
    _detail = aDetailView;


    [self.view addSubview:_detail.view];
    //I never really set it to setHidden:YES, but just to make sure I'm setting it NO here.
    [_detail.view setHidden:NO];
    return _detail;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView transitionFromView:self.view toView:self.detail.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
}

输出:

2012-02-07 11:17:51.909 TodoApp[4232:fb03] Detail UIView construction started.

该视图似乎可以很好地执行 FlipFromRight 动画,但屏幕是全黑的。 正如我所说,我不擅长以编程方式改变视图。

感谢您的帮助!

============= 回答我自己的问题。

实在是太蠢了。标题栏中的“后退”按钮具有不受支持的配置。所以视图不想加载...现在修复它。

Here is a small problem I am having. I am not too good at programmatically changing views, but this is what I have:

//(.h)


#import <UIKit/UIKit.h>
#import "Detail.h"

@interface List : UIViewController <UITableViewDelegate, UITableViewDataSource>
{

}

@property (retain, nonatomic) IBOutlet UITableView *tableView;
@property (retain, nonatomic) Detail *detail;
@end

and

//(.m)
@synthesize detail=_detail;

- (Detail *)detail
{
    NSLog(@"Detail UIView construction started.");
    if (_detail != nil)
    {
        return _detail;
    }

    Detail *aDetailView = [[Detail alloc] init];
    _detail = aDetailView;


    [self.view addSubview:_detail.view];
    //I never really set it to setHidden:YES, but just to make sure I'm setting it NO here.
    [_detail.view setHidden:NO];
    return _detail;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView transitionFromView:self.view toView:self.detail.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
}

As output:

2012-02-07 11:17:51.909 TodoApp[4232:fb03] Detail UIView construction started.

The view seems to do the FlipFromRight animation fine, but the screen is totally black.
As I said, I'm not good at changing views programmatically.

Thanks for any help!

=============
Answering my own question.

It was really stupid. The "Back" button in the Title bar had an unsupported configuration. So the View did not want to load... fixed it now.

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

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

发布评论

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

评论(3

落日海湾 2025-01-10 13:26:39
- (Detail *)detail
{
NSLog(@"Detail UIView construction started.");
if (_detail != nil)
{
    return _detail;
}

Detail *aDetailView = [[Detail alloc] init];
[self.view addSubview:aDetailView.view];
//I never really set it to setHidden:YES, but just to make sure I'm setting it NO here.
[aDetailView.view setHidden:NO];
_detail = aDetailView;

return _detail;
}

进行这些更改并让我知道结果..

- (Detail *)detail
{
NSLog(@"Detail UIView construction started.");
if (_detail != nil)
{
    return _detail;
}

Detail *aDetailView = [[Detail alloc] init];
[self.view addSubview:aDetailView.view];
//I never really set it to setHidden:YES, but just to make sure I'm setting it NO here.
[aDetailView.view setHidden:NO];
_detail = aDetailView;

return _detail;
}

make these changes and let me know the result..

温柔一刀 2025-01-10 13:26:39

您在将 _detail 添加到超级视图之前返回它,

因此添加此行

return _detail;

在这一行之后 [self.view addSubview:_detail.view];

像这样

[self.view addSubview:_detail.view];

[_detail.view setHidden:NO];

return _detail;

you are returning _detail before adding it to superview

so add this line

return _detail;

after this line [self.view addSubview:_detail.view];

like this

[self.view addSubview:_detail.view];

[_detail.view setHidden:NO];

return _detail;
不即不离 2025-01-10 13:26:39

回答我自己的问题。

实在是太蠢了。标题栏中的“后退”按钮具有不受支持的配置。所以视图不想加载...现在修复它。

Answering my own question.

It was really stupid. The "Back" button in the Title bar had an unsupported configuration. So the View did not want to load... fixed it now.

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