加载没有Xib的UIViewController

时间:2013-02-04 06:33:24

标签: objective-c uiviewcontroller

如果UIViewController没有连接到xib,我有一个类是子类,

该类包含一个presentViewController TWTweetComposeViewController实例的方法(用于发送推文)。

因此,当我需要调用该方法时,我需要使用presentViewController来呈现视图,但它不起作用,这就是我正在做的事情:

//这是B类(UIViewController的子类)

中的方法
@implementation TwitterManager
-(id)init
{
    self = [super init];

    if(self)
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postTweetImage:) name:Twitter_UploadImage object:nil];
    }

    return self;
}

+(TwitterManager*)sharedInstance
{
    if(object == nil)
        object = [[TwitterManager alloc] init];

    return object;
}
-(void)postTweet
{
    if([TWTweetComposeViewController canSendTweet])
    {
        NSLog(@"can send tweet postTweet");
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];

        // Set the initial tweet text. See the framework for additional properties that can be set.
        [tweetViewController setInitialText:@"Hello. This is a tweet."];

        // Create the completion handler block.
        [tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            NSString *output;

            switch (result) {
                case TWTweetComposeViewControllerResultCancelled:
                    // The cancel button was tapped.
                    output = @"Tweet cancelled.";
                    break;
                case TWTweetComposeViewControllerResultDone:
                    // The tweet was sent.
                    output = @"Tweet done.";
                    break;
                default:
                    break;
            }

            //[self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];

            // Dismiss the tweet composition view controller.
            [self dismissViewControllerAnimated:YES completion:nil];
        }];

        // Present the tweet composition view controller modally.
        [self presentViewController:tweetViewController animated:YES completion:nil];
    }
    else
    {
        NSLog(@"can not sen a tweet");
    }
}
@end

//在A班我试图像这样称呼它

TwitterManager twitterObject = [TwitterManager sharedInstance];
    [twitterObject postTweet];

那么创建负责加载Twitter对象的视图的方法是什么presentViewController

1 个答案:

答案 0 :(得分:0)

YourTweetViewController * tweetViewController = [[YourTweetViewController alloc]init];
[self presentViewController:tweetViewController animated:YES completion:nil];