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



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

//(.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动画,但屏幕完全是黑色的。正如我所说,我不擅长以编程方式更改视图。

谢谢你的帮助!

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

这真的很愚蠢。标题栏中的"后退"按钮的配置不受支持。所以视图不想加载。。。现在修复它。

- (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添加到superview 之前,您将返回_detail

所以加上这行

return _detail;

此行之后[self.view addSubview:_detail.view];

像这个

[self.view addSubview:_detail.view];
[_detail.view setHidden:NO];
return _detail;

回答我自己的问题。

这真的很愚蠢。标题栏中的"后退"按钮的配置不受支持。所以视图不想加载。。。现在修复它。

最新更新