Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c if语句中的异常条件表达式_Objective C - Fatal编程技术网

Objective c if语句中的异常条件表达式

Objective c if语句中的异常条件表达式,objective-c,Objective C,我理解如果[sender.currentTitle length]非零,if语句将继续。然而,这里涉及的语法让我感到困惑 - (IBAction)touchCardButton:(UIButton *)sender { if ([sender.currentTitle length]) { UIImage *cardImage = [UIImage imageNamed:@"cardback"]; [sender setBackgroundImage:cardIm

我理解如果[sender.currentTitle length]非零,if语句将继续。然而,这里涉及的语法让我感到困惑

- (IBAction)touchCardButton:(UIButton *)sender
{
   if ([sender.currentTitle length]) {

      UIImage *cardImage = [UIImage imageNamed:@"cardback"];
      [sender setBackgroundImage:cardImage forState:UIControlStateNormal];

      [sender setTitle:@"" forState:UIControlStateNormal];
      }
}
或者用点语法

[sender currentTitle] 
检查按钮“发送者”的标题。但是长度在这里做什么呢?长度是一种方法吗?长度是否返回值?是否等同于:

sender.currentTitle

这没有什么不寻常的

sender.currentTitle
返回作为按钮标题的NSString。正如您所注意到的,这相当于
[sender currentTitle]
。在这两种情况下,您都在调用
sender
上的
currentTitle
方法。因此,
[sender.currentTitle length]
调用NSString上的
length
方法,该方法是调用
sender
上的
currentTitle
的结果,并返回字符串长度的整数

另一种书写方式是:

[[sender currentTitle] length] 
或者进一步细分:

NSString *title = sender.currentTitle;
if ([title length] > 0) {
  // Do something if the length is not zero.
}
如果您只是这样做:

NSString *title = sender.currentTitle;
NSUInteger length = [title length];
if (length > 0) {
  // Do something if the length is not zero.
}

如果按钮的当前标题不是
nil
,则您的条件为true,这与长度>0相同。

这没有什么不寻常之处

sender.currentTitle
返回作为按钮标题的NSString。正如您所注意到的,这相当于
[sender currentTitle]
。在这两种情况下,您都在调用
sender
上的
currentTitle
方法。因此,
[sender.currentTitle length]
调用NSString上的
length
方法,该方法是调用
sender
上的
currentTitle
的结果,并返回字符串长度的整数

另一种书写方式是:

[[sender currentTitle] length] 
或者进一步细分:

NSString *title = sender.currentTitle;
if ([title length] > 0) {
  // Do something if the length is not zero.
}
如果您只是这样做:

NSString *title = sender.currentTitle;
NSUInteger length = [title length];
if (length > 0) {
  // Do something if the length is not zero.
}

如果按钮的当前标题不是
nil
,则您的条件为true,这与长度>0相同。

这没有什么不寻常之处

sender.currentTitle
返回作为按钮标题的NSString。正如您所注意到的,这相当于
[sender currentTitle]
。在这两种情况下,您都在调用
sender
上的
currentTitle
方法。因此,
[sender.currentTitle length]
调用NSString上的
length
方法,该方法是调用
sender
上的
currentTitle
的结果,并返回字符串长度的整数

另一种书写方式是:

[[sender currentTitle] length] 
或者进一步细分:

NSString *title = sender.currentTitle;
if ([title length] > 0) {
  // Do something if the length is not zero.
}
如果您只是这样做:

NSString *title = sender.currentTitle;
NSUInteger length = [title length];
if (length > 0) {
  // Do something if the length is not zero.
}

如果按钮的当前标题不是
nil
,则您的条件为true,这与长度>0相同。

这没有什么不寻常之处

sender.currentTitle
返回作为按钮标题的NSString。正如您所注意到的,这相当于
[sender currentTitle]
。在这两种情况下,您都在调用
sender
上的
currentTitle
方法。因此,
[sender.currentTitle length]
调用NSString上的
length
方法,该方法是调用
sender
上的
currentTitle
的结果,并返回字符串长度的整数

另一种书写方式是:

[[sender currentTitle] length] 
或者进一步细分:

NSString *title = sender.currentTitle;
if ([title length] > 0) {
  // Do something if the length is not zero.
}
如果您只是这样做:

NSString *title = sender.currentTitle;
NSUInteger length = [title length];
if (length > 0) {
  // Do something if the length is not zero.
}

如果按钮的currentTitle不是
nil
,则您的条件为true,这与长度>0不一样。

在Objective-C中,
只是调用setter/getter的语法糖,它不像在Swift中那样是字段访问器(这个问题是否早于Swift?)


在您的代码片段中,调用了
currentTitle
的getter,并对该字符串调用了
length
方法。

在Objective-C中,
只是调用setter/getter的语法糖,它不像在Swift中那样是字段访问器(这个问题是否早于Swift?)


在您的代码片段中,调用了
currentTitle
的getter,并对该字符串调用了
length
方法。

在Objective-C中,
只是调用setter/getter的语法糖,它不像在Swift中那样是字段访问器(这个问题是否早于Swift?)


在您的代码片段中,调用了
currentTitle
的getter,并对该字符串调用了
length
方法。

在Objective-C中,
只是调用setter/getter的语法糖,它不像在Swift中那样是字段访问器(这个问题是否早于Swift?)



在您的代码片段中,调用了
currentTitle
的getter,并对该字符串调用了
length
方法。

我在所有地方搜索了Apple文档,它与生活一样平常,只要检查标题的长度,如果它为零,请继续。这有什么奇怪的?好吧,但在这种情况下长度是多少?留言?当然是,你为什么不检查一下文件?我到处搜索苹果的文档,就像往常一样,只是检查标题的长度,如果没有,继续。这有什么奇怪的?好吧,但在这种情况下长度是多少?留言?当然是,你为什么不检查一下文件?我到处搜索苹果的文档,就像往常一样,只是检查标题的长度,如果没有,继续。这有什么奇怪的?好吧,但在这种情况下长度是多少?留言?当然是,你为什么不检查一下文件?我到处搜索苹果的文档,就像往常一样,只是检查标题的长度,如果没有,继续。这有什么奇怪的?好吧,但在这种情况下长度是多少?留言?当然是,你为什么不检查一下文件?如果NSClarification是一个类,则itd返回一个100的整数