无法从另一个Viewcontroller发布推文

时间:2011-07-09 17:07:49

标签: ios twitter-oauth

我正在使用Outh将Twitter添加到我的应用中。

下面是两个分别用于登录和发布推文的UIViewControllers。

1.SettingViewcontroller  2.DetailViewcontroller

此代码用于使用SettingViewcontroller登录到twitter。

- (void)switchAction1:(UISwitch*)sender
   {
   if (sender.on)
    {
           if(_engine) 
       return;

      _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]
   _engine.consumerKey = @"###";
    _engine.consumerSecret = @"###"; 

   UIViewController *controller =[SA_OAuthTwitterController  controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];

   DetailViewcontroller *detobj=[[DetailViewcontroller alloc]init];

 detobj.detail_enginne=_engine; 

   [detobj release];

    [self presentModalViewController: controller animated: YES];
   }
  if(!sender.on)
  { 

NSLog(@"Logout section");

    }
}

并且在DetailViewcontroller中,当操作表按钮cliked时,将执行以下代码。

    if ([detail_enginne isAuthorized]) 
    { 
      NSLog(@"engine availble");

               NSString *str=@"hai twitterrrrrrrrrrr";

             [detail_enginne sendUpdate:str];

    }
    else{
        NSLog(@"Engine not availabele");
             }  
}

此处我无法从DetailViewcontroller发送推文。

如何实现这个目标?

更新

Iam loding使用ViewDidload而非Nib的详细信息视图。

Detailview.m

这是用于从DetailView

向Facebook和Twitter发布数据的actionSheet方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    // For  facebook
if(buttonIndex == 0)
{


    if ([session resume])  {


        [self postToWall];

        NSLog(@"Post to wall");

    }
    else {

        self.loginDialog = nil;
        _loginDialog = [[FBLoginDialog alloc] init];    
        [_loginDialog show];

    }


}                           

//  For twittter
  if(buttonIndex == 1)
  {         
    if(detail_enginne!=nil) 
    { 

        NSString *str=@" hai twitter  ";
        [detail_enginne sendUpdate:str];

    }
    else 
    {
        NSLog(@"Not availabele");

    }
}
if(buttonIndex == 2)
{

    NSLog(@"cancel button ");


}
   }

1 个答案:

答案 0 :(得分:0)

First Thing是获取用户凭据的地方吗?

我不知道,为了您检查按钮索引的目的。 你也尝试这样做,

if ([detail_enginne isAuthorized])
{
  NSLog(@"engine availble");
  NSString *str=@"hai twitterrrrrrrrrrr";
  [detail_enginne sendUpdate:str];
}
 else
{
   NSLog(@"Engine not availabele");
}  

从您的代码中

    - (void)switchAction1:(UISwitch*)sender
       {
       if (sender.on)
        {
               if(_engine) 
           return;

          _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]
         _engine.consumerKey = @"###";
          _engine.consumerSecret = @"###"; 

         UIViewController *controller =[SA_OAuthTwitterController  controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
     if(controller)
{
    [self presentModalViewController: controller animated: YES]; //Here You will show your login screen twitter
}


//After getting credentials , You do this

   DetailViewcontroller *detobj=[[DetailViewcontroller alloc]init];

     detobj.detail_enginne=_engine;  // this **detobj** should be used for presenting detailView

       [detobj release];
       }
      if(!sender.on)
      { 

    NSLog(@"Logout section");

        }
    }