从 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 动画,但屏幕是全黑的。 正如我所说,我不擅长以编程方式改变视图。
感谢您的帮助!
============= 回答我自己的问题。
实在是太蠢了。标题栏中的“后退”按钮具有不受支持的配置。所以视图不想加载...现在修复它。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
进行这些更改并让我知道结果..
make these changes and let me know the result..
您在将 _detail 添加到超级视图之前返回它,
因此添加此行
return _detail;
在这一行之后 [self.view addSubview:_detail.view];
像这样
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
回答我自己的问题。
实在是太蠢了。标题栏中的“后退”按钮具有不受支持的配置。所以视图不想加载...现在修复它。
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.