我知道这很可能是一个蹩脚的问题,但我已经连续三个通宵了,我很模糊。我是 Objective C 和 Cocoa Touch 的新手。
我创建了一个提供委托方法的类。我将使用简化的示例代码,因为细节并不重要。头文件如下所示:
#import <Foundation/Foundation.h>
@protocol UsernameCheckerDelegate <NSObject>
@required
- (void)didTheRequestedThing:(BOOL)wasSuccessful;
@end
@interface TheDelegateClass : NSObject {
id <TheDelegateClassDelegate> tdcDelegate;
}
@property (assign) id <TheDelegateClassDelegate> tdcDelegate;
- (void)methodThatDoesSomething:(int)theValue;
@end
源文件如下所示:
#import "TheDelegateClass.h"
@implementation TheDelegateClass
@synthesize tdcDelegate;
- (void)methodThatDoesSomething:(int)theValue {
if (theValue > 10) {
[[self tdcDelegate] didTheRequestedThing:NO];
// POINT A
}
// POINT B
int newValue = theValue * 10;
NSString *subject = [NSString stringWithFormat:@"Hey Bob, %i", newValue];
// Some more stuff here, send an email or something, whatever
[[self tdcDelegate] didTheRequestedThing:YES];
// POINT C
}
@end
这是我的问题:如果theValue实际上大于 10 并且 POINT A 上方的行运行,程序流控制是从该方法传递出去(并返回到调用 this 的对象中的didTheRequestedThing委托方法)还是继续流B点到C点?
我希望是前者,因为我可以简化我的代码,目前是深度嵌套的 if 和 else 令人不快的混乱。