我想通过TWTweetComposeViewController在没有弹出对话框的情况下发推文

时间:2012-03-30 10:33:08

标签: ios5 twitter

我想发布在Twitter墙上,但不希望用户可以编辑发布的消息。

因此有两种可能性

1)我可以使TWTweetComposeViewController文本字段不可编辑。

2)TWTweetComposeViewController发布没有POP的帖子。

请建议我如何做出以上选项或任何其他想法最受欢迎。

预先感谢任何类型的建议......

2 个答案:

答案 0 :(得分:3)

我通过以下代码完成了这个......

-(void)postToTwittert:(NSString *)stringtoPost
{    
    Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

    if (TWTweetComposeViewControllerClass != nil) {
        if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
            TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];

            [twitter setInitialText:stringtoPost];

            [twitter addImage:[UIImage imageNamed:@"apple.jpg"]];
            [twitter addURL:[NSURL URLWithString:@"http://www.erwinzwart.com"]];
            [self findSubViewofTwitter:twitter.view];
            [self presentViewController:twitter animated:YES completion:nil];

            twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {

                if(res == TWTweetComposeViewControllerResultDone)
                {
                    [self completeGameStep:@"glueper2012"];                    

                }
                else if(res == TWTweetComposeViewControllerResultCancelled)
                {

                    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Canceled" message:@"Your Tweet was not posted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

                    [alertView show];

                }

                [self dismissModalViewControllerAnimated:YES];

            };
        }
    } 
}

通过查找按钮和触发事件

    - (void) findSubViewofTwitter:(UIView*)theView
{
    for (UIView * subview in theView.subviews)
    {
        //NSLog(@">>>>>>>>>>>>>>>>>> :%@", subview);
        if ([subview isKindOfClass:[UIButton class]])
        {
            UIButton *btn = (UIButton *)subview;
            //NSLog(@">>>>>>>>>>>>>> is kind of class :%@", btn.titleLabel.text);
            if([btn.titleLabel.text isEqualToString:@"Send"])
            {
                [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
            }
        }
        [self findSubViewofTwitter:subview];
    }
}

答案 1 :(得分:3)

我修改了你的函数“findSubViewofTwitter”,以便在不等待用户按下发送的情况下不发送推文。我的函数只是使UITextView不可编辑。

- (void) findSubViewofTwitter:(UIView*)theView
{
    for (UIView * subview in theView.subviews)
    {
        if ([subview isKindOfClass:[UITextView class]])
        {
            UITextView *textView = (UITextView *)subview;
            textView.editable = NO;
            return;
        }
        [self findSubViewofTwitter:subview];
    }
}