MFMessageComposeViewController setting the UINavigationItem titleView
I'm having a problem overriding the title view of MFMessageComposeViewController's navigation item. Here is the code:
MFMessageComposeViewController *messageViewController = [[MFMessageComposeViewController alloc] init];
messageViewController.body=@"SMS Body";
CGRect frame = CGRectMake(0, 0, 100.0, 45.0);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.text=@"Title";
messageViewCont开发者_开发问答roller.navigationItem.titleView=label;
[label release];
[self.navigationController presentModalViewController:messageViewController animated:YES];
[messageViewController release];
I have also tried: messageViewController.navigationController.navigationItem.titleView=label;
I should also point out that this is for iOS 4, in iOS 5 I use the new setTitleTextAttributes method which works great.
Thoughts?
I believe this semi-hack should produce the desired effect. Since we know that MFMessageComposeViewController
is a subclass of UINavigationController
, the view that you are actually seeing must be managed by a private controller class. You should be able to modify that controllers navigation item in order to achieve what you want.
messageViewController.topViewController.navigationItem.titleView = label;
In my testing, this only worked with the titleView. If you just try to set the title, it will work for a couple seconds, but then gets overriden back to the title of the email. As with any other sort of UIKit hacks, this could stop working at any time, and it may only work on particular OS versions.
精彩评论