如果满足条件,Obj-C停止程序

时间:2014-05-29 10:48:47

标签: objective-c xcode5 ios7.1

if (stash != 0) {
            for (i=1; i<=6; i++) {
                a[1][i]=a[1][i]/stash;
            }
        }
        else
        {
            NSLog (@"Matrix is Not Invertible");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Matrix is not invertible!" delegate:nil cancelButtonTitle:@"Review Input" otherButtonTitles:nil, nil];
            [alert show];

        }

如果变量&#34; stash&#34;我想停止程序是零,但我不能使用break,因为它不在循环中,我想使用return但它说void不应该返回任何值...我应该怎么做才能使它工作?谢谢你的帮助......

2 个答案:

答案 0 :(得分:0)

我不知道您是否只需退出该方法,但您可以使用:

return;

或重新定义方法以返回整数-(int)myMethod;,然后返回0;

答案 1 :(得分:0)

//Add return statement, returning nothing
return;



- (void)yourMethod {


  //your code


  //your declerations

  if (stash != 0) {
    for (i=1; i<=6; i++) {
      a[1][i]=a[1][i]/stash;
    }
  }
  else
  {
    NSLog (@"Matrix is Not Invertible");
    UI *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Matrix is not invertible!" delegate:nil cancelButtonTitle:@"Review Input" otherButtonTitles:nil, nil];
    [alert show];

    //Add return statement here, returning nothing
    return;
  }


   //other code in your method
   //your code

}
相关问题