0

UIViewController如果没有 xib 连接到它,我有一个作为子类的类,,,

该类包含一个方法,该方法将是(to make a tweet)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

// 在 AI 类中,我试图这样称呼它

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

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

4

1 回答 1

0
YourTweetViewController * tweetViewController = [[YourTweetViewController alloc]init];
[self presentViewController:tweetViewController animated:YES completion:nil];
于 2013-02-04T06:52:16.003 回答