English 中文(简体)
代表制 A 但没有控制人B
原标题:Delegate works in controller A but not in controller B

这是代表。

@protocol DropControllerDelegate;

@interface DropController : NSObject
   id<DropControllerDelegate> delegate;
}

@property (nonatomic, assign) id<DropControllerDelegate> delegate;
+ (DropController*) sharedController;

@protocol DropControllerDelegate <NSObject>
- (void)openUserButtons;
- (void)startUpload;
- (void)uploadDone;
- (void)uploadFailed;
- (void)startDownload;
- (void)downloadDone;
- (void)subFolderLoaded;
@end

这是单一州法典:

static DropController *sharedCont = nil;

#pragma mark Singleton stuff

+ (DropController *) sharedController {
    @synchronized(self)     {
        if (!sharedCont)
            sharedCont = [[DropController alloc] init];
        return sharedCont;
    }
    return sharedCont;
}

The code to set the delegate is (in both myControllerA and myControllerB):

DropController* dropHelper = [DropController sharedController];
dropHelper.delegate = self;

我能够接受一名控制员的电话,但不能在另一名控制员身上(这部法律是一张影印机),这正促使我cra!

最佳回答

正如我在评论中所说的那样,由于你正在使用该物体的共同事例,它将超越原先指定的新物体的代表。 因此,我建议在你们的共有中占有一席之地。 主计长。 加入这一阵列,希望成为共有主计长的代表。

Then iterate through that array and call the method over each object in it. Its pretty simple.


Edit:

您在<条码>上指派代表时 缩略语 反对A成为代表。 要求使用<代码>[替代开放式UserButtons];将触发<编码>查询器上的方法。 A。 但是,如果您填写了dropHelper.delegate = Self; in view Controller B,[delegate openUserButtons];将使用标B中的方法。 它不会把这两种方法从a和b中划出。 由于只有一个代表变量,你正在使用一个共用的单一吨标。

问题回答

暂无回答




相关问题
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, ...

热门标签