How to customize TTMessageController fields?
I use the TTMessageController to get an recipient picker and a text area for writing sms messages. However there is still this "subject" field that I do not need.
How do I remove it?
This is how I create TTMessageController:
self.second [[SecondViewController alloc] init];
[self开发者_开发知识库.second release];
UINavigationViewController *navigationController =
[[UINavigationController alloc]
initWithRootViewController:self.second];
[self presentModalViewController:navigationController animated:YES];
SecondViewController is a subclass of TTMessageController. So how do I customize it to remove/add fields, especially the subject field?
Create a subclass of TTMessageController and override the initWithNibName. In your overidden initWithNibName method set the _fields array to keep just the fields you want to have. The example below will keep only the To: field.
///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.dataSource = [[AddressBookDataSource new] autorelease];
_fields = [[NSArray alloc] initWithObjects:
[[[TTMessageRecipientField alloc] initWithTitle: TTLocalizedString(@"To:", @"")
required: YES] autorelease], nil];
self.showsRecipientPicker = YES;
self.title = TTLocalizedString(@"New Message", @"");
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle: TTLocalizedString(@"Cancel", @"")
style: UIBarButtonItemStyleBordered
target: self
action: @selector(cancel)] autorelease];
}
return self;
}
精彩评论