English 中文(简体)
内容提要:目标C的活动聆听者的情况如何?
原标题:iOS: what is the equivalent of an event listener in Objective-C?

在我的一些学习中,我看到有人提到,在你看来,控制者可以有一个模式,并且能够就模式的改变进行某种聆听。 我不认为我是用正确的名字来看待我,这很可能是为什么我的搜索避而不谈。 基本上,我想把我的服务器电话从控制器转到我的模型中,但我需要一些听众来了解这一呼吁何时能完成更新我的看法。

最佳回答

look into delegates delegates tutorial

or blocks a bit more advanced basic blocks tutorial

仅从代表开始,

也可使用国家公告,但并不建议向每一阶层广播。

问题回答

Belong to C# world, i have to go to objective c (for my job). I think the event equivalent in objective c is this implementation :

1. 订立与你的所有活动方法相同的议定书:

@protocol MyDelegate <NSObject>
    - (void)myEvent;
@end

在您的级别上,加上:

@interface MyClassWichSendEvent : NSObject

@property (nonatomic, retain) IBOutlet id<MyDelegate> delegate;

@end

Raising the event where you want, for example :

- (IBAction)testEvent:(NSButton*)sender
{
    [self.delegate myEvent];
}

现在,在你们的听众中,你们应该倾听这样的活动:

将议定书添加到你的听众中

@interface Document : NSDocument<MyDelegate>

在执行过程中,在 in或接口建设商上,你必须把你的标本的代表与你的听众本人联系起来。

守则

-(void)awakeFromNib
{
    myObjToListen.delegate = self;    
}
  • In Interface Builder -> IBOutlet from delegate to your listen s class.

最后,在你的听众中执行你的方法:

- (void)myEvent
{
    NSLog(@"i have listen this event !");
}

给我的办公室工作,希望能帮助那些从小ava或C#出发的人。

我认为,你可以寻找国家核电中心,这是向谁传递信息的一种方式。 因此,你可以从你模式中发出通知,并在你的控制人中听取通知。 更清洁的方法可能是与代表执行自己的议定书。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签