如何自定义TTMessageController字段?

时间:2011-03-24 11:24:02

标签: iphone xcode three20

我使用TTMessageController获取收件人选择器和用于编写短信的文本区域。但是,我仍然不需要这个“主题”字段。

如何删除它?

这是我创建TTMessageController的方式:

self.second [[SecondViewController alloc] init];
[self.second release];

UINavigationViewController *navigationController = 
              [[UINavigationController alloc]
               initWithRootViewController:self.second];
[self presentModalViewController:navigationController animated:YES];

SecondViewController是TTMessageController的子类。那么如何自定义它以删除/添加字段,尤其是主题字段?

1 个答案:

答案 0 :(得分:1)

创建TTMessageController的子类并覆盖initWithNibName。在覆盖的initWithNibName方法中,设置_fields数组以仅保留您想要的字段。以下示例仅保留To:字段。

///////////////////////////////////////////////////////////////////////////////////////////////////
- (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;
}