如何一次传递一个NSInteger参数?

时间:2014-05-06 13:35:40

标签: ios objective-c for-loop

我需要一次将myInteger传递给一个参数,而不是传递另一个myInteger,直到调用完syncDocFinish函数。所以基本上这个代码将被调用一次[self syncDocs:myInteger];,然后在syncDocs函数完成之前不会再次调用它。

 - (void) syncDocs
 {
int i;
for (i = 0; i < [mFormList count]; i++) {   
    myInteger = i;
    [self syncDocs:myInteger];  
}
 }

-(void)syncDocs : (NSInteger) myInt{

[docHandler getDocs:myInt limit:InitLoad_Count];

// the doc handler will call syncDocFinish automatically
 }


 - (void) syncDocFinish : (id) result
 {

 /// do functions{
  }
 /// sync doc is finished insert code to call [self syncDocs:myInteger];  again

    }

3 个答案:

答案 0 :(得分:0)

int myInteger = 0; // initialise as class level local variable

-(void)syncDocs {

    [docHandler getDocs:myInteger limit:InitLoad_Count];

    // the doc handler will call syncDocFinish automatically
}
- (void) syncDocFinish : (id) result {

     // do functions{
     //}
     /// sync doc is finished insert code to call [self syncDocs:myInteger]; 

if(myInteger < [mFormList count]){
  myInteger ++;
  [self syncDocs];   
}
}
This should be work...

答案 1 :(得分:-1)

你可以简单地使用BOOL值。

BOOL isSyncDocFinish;

   - (void) syncDocs
 { 
    int i;
    for (i = 0; i < [mFormList count]; i++) {   
    myInteger = i;
    if(isSyncDocFinish)
    {
     isSyncDocFinish = NO;
     [self syncDocs:myInteger]; 
    } 
  }
}

       -(void)syncDocs : (NSInteger) myInt
        {

         [docHandler getDocs:myInt limit:InitLoad_Count];

        // the doc handler will call syncDocFinish automatically
        }


      - (void) syncDocFinish : (id) result
        {
             isSyncDocFinish = YES;
      /// do functions{
        }
       /// sync doc is finished insert code to call [self syncDocs:myInteger];  again

   }

答案 2 :(得分:-1)

为此任务提供了几种解决方案:

  1. 代表
  2. 通知
  3. 具有相关操作的NSOperationQueue
  4. 发送信号量
  5. 我不会详细描述这些内容,因为互联网上有很多关于它的信息。  我建议搜索&#34;如何使用NSOperation依赖&#34;或阅读此NSOperation howto

相关问题