【问题标题】:Method is not getting called twice in IOS方法在 IOS 中没有被调用两次
【发布时间】:2013-05-02 05:27:09
【问题描述】:

我正在 IOS 中进行 Instagram 集成。一切顺利。我正在获取用户的提要并在 tableview 和滚动视图中显示它们。这里允许用户刷新页面。同时刷新方法没有被调用并且由于数组中的零个对象而崩溃。我使用以下代码调用该方法。

-(IBAction)loginAction:(id)sender
{
        AppDelegate* appDelegate_new = (AppDelegate*)[UIApplication sharedApplication].delegate;
      [appDelegate_new.instagram authorize:[NSArray arrayWithObjects:@"comments", @"likes", nil]];


      if ([appDelegate.instagram isSessionValid]) {

    //  NSLog(@"ViewDidLoad Session Valid");

          loginView.hidden=YES;
          crossButton.hidden=YES;
          settingsButton.hidden=NO;
          noticeView.hidden=YES;

          [self.view addSubview:feedsView];
         // [self.logOutView removeFromSuperview];
          self.feedsView.frame=CGRectMake(0, 0, 240, 300);
          NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"users/self/feed", @"method", nil];
          [appDelegate.instagram requestWithParams:params
                                    delegate:self];
    } 
}

调用的方法是这样的

      - (void)request:(IGRequest *)request didLoad:(id)result
      {

          [self performSelector:@selector(startspinner) withObject:nil afterDelay:0.1];
          self.data = (NSMutableArray *)[result objectForKey:@"data"];
        // NSLog(@"Data Count is %@",[self.data description]);
          createdArray=[[NSMutableArray alloc]init];

        //*****Here I am performing Json Parsing******//

      }

我在刷新时再次调用上述请求方法

    - (void)dropViewDidBeginRefreshing:(ODRefreshControl *)refreshControl
      {
            [createdArray removeAllObjects];

            NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"users/self/feed", @"method", nil];
            [appDelegate.instagram requestWithParams:params
                                delegate:self];
            [self performSelector:@selector(refreshData) withObject:nil afterDelay:5.0];
      }

请告诉我哪里出错了。感谢指正。在此先感谢。

【问题讨论】:

  • 你每次调用哪个方法?
  • @jack :检查我的答案。
  • @Sunny 抱歉回复晚了..正在开会...我正在打电话 - “(void)request:(IGRequest *)request didLoad:(id)result” 每次..
  • 你为什么要调用 requestDidLoad 呢?当请求最终完成时,请求不应该调用它吗?您在何时何地发生崩溃?
  • 它在表格视图中......如果数组计数为零,那么它就会崩溃。这是因为我正在解析请求方法本身的数据。但是它没有被称为@HermannKlecker

标签: iphone ios objective-c ipad instagram


【解决方案1】:

试试看……

[NSTimer scheduledTimerWithTimeInterval:0.5f
                                 target:self
                               selector:@selector(showTime)
                               userInfo:NULL
                                repeats:YES];

- (void)showTime
{
    NSLog(@"Method called");
}

经常使用 NSTimer 作为调用方法。
希望我有所帮助。

【讨论】:

  • 你的答案超出了我的要求,伙计.. @Chirag
  • @Jack1231 :您可以使用我的答案多次调用方法。你到底想要什么?
  • 它按照上述时间调用..但是当我点击刷新按钮时应该调用它.. @Chirag
  • @Jack1231 : 设置时间 0.01 它会立即被调用。
  • @Jack1231 :将 nstimer 代码添加到刷新按钮中,它将起作用。
猜你喜欢
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
  • 2013-12-31
  • 1970-01-01
  • 2012-12-26
  • 2020-07-16
  • 2014-09-02
  • 1970-01-01
相关资源
最近更新 更多