【问题标题】:How do you "abort" a method in Objective C? [closed]您如何“中止”Objective C 中的方法? [关闭]
【发布时间】:2012-12-28 00:36:02
【问题描述】:

我知道有办法解决这个问题,但我想知道以下问题是否可行。你能在 Objective-C 中“中止”一个方法吗?在这种情况下,它是在 Cocoa Touch 上。我有一个 IBAction。在那个动作中,我有 if/else if/else 语句。如果不是这样,我想中止该方法的其余部分。有点像 return 0,但用于 IBAction。

这可能吗?如果是这样,你将如何做到这一点。整个方法有点长,但这是我正在查看的部分:

if ([unitType isEqualToString:@"mg/dl"])
    {
        //Unit is mg.
        typeOfUnit = unitType;
    }
    else if ([unitType isEqualToString:@"mmol"])
    {
        //Unit is mmol
        typeOfUnit = unitType;
    }
    else
    {
        //Apparently either a bug or a (null) item.
        typeOfUnit = @"mg/dl";
        [[LEItemStore sharedStore] createItem];
        item = [[[LEItemStore sharedStore] allItems] objectAtIndex:0];
        [self loadItems:self];

        //Code to Abort the rest of the method here.
    }

谢谢。

【问题讨论】:

  • “回归”? .....
  • @MitchWheat, . . .好吧……失败。呃。我会恨自己一辈子。谢谢。将其发布为答案。
  • 是的。他是对的。你应该使用 return。
  • @AceLegend :D——关于 SO 有更糟糕的问题
  • 现在等待关于return 的17 个答案滚进来。

标签: objective-c cocoa-touch ibaction abort


【解决方案1】:

很简单:

return;

(太简单了,没有这句话就发帖太短了。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2011-09-16
    相关资源
    最近更新 更多