I want to add a subview programmatically to my view, FirstViewController.xib
. For now this is how it开发者_运维知识库 looks like
When I click on the compose button another view, SecondViewController.xib
, pops up from the bottom. It has a navigation bar similar to what you see in the picture.
No I want to add a subview:
TTMessageController* controller = [[[TTMessageController alloc]
initWithRecipients:nil] autorelease];
[self.view addSubview:controller.view]
However I get a strange result. The controller.view
is overlapping the sidebar:
How can I solve that problem so that the navigation bar is visible.
Adding a UIViewController's (or subclasses') view to another UIView isn't how Apple recommend you present view controller's views -- it means things like orientation change detection can misbehave, etc. Apple say that you shouldn't have more than one view controller responsible for any one 'screen' of content.
The usual way to present the standard mail controller interace is by presenting it as you would a normal UIViewController (e.g. modally, or pushing on a nav stack, etc.) -- and I suggest that the same advice goes for the Three20 mail composer too.
The advice I give in my answer here is related:
iPhone, Obj-C, How can I use in app email from an actionsheet button click while using addSubview?
You need to push the frame of the subview down:
CGRect frame = controller.view.frame;
frame = CGRectMake(0, 40, frame.size.width, frame.size.height);
controller.view.frame = frame;
The 40
value above is the y-value of the view's origin and should be adjusted accordingly to suit your needs.
精彩评论