English 中文(简体)
试图设定财产价值,但无
原标题:Trying to set a property value, but it s nil

我在主计长的主档案中宣布了一项管理地图观点的议定书。

@protocol UCMapViewDelegate <NSObject>
@required
- (void)pushMapviewRight;

@end

I m 在另一个观点控制人(h)中宣布执行该议定书,并在档案中执行

// in the UCRootViewController.h
@interface UCRootViewController : UIViewController <UCMapviewDelegate>

// in the UCRootViewController.m
- (void)pushMapviewRight
{
    NSLog(@"push mapview right");
}

我把该代表交给一个标明问题根基的主计长的财产。 我的地图主计长认为DidLoad()是这样做的,其财产为@property(weak, nonatomic)id<UCMapViewDelegate>代表;

// in UCRootViewController
self.mapviewController.rootviewController = self;

// in UCMapViewController
self.delegate = (id<UCMapviewDelegate>)self.rootviewController;

• 地图概览中一个纽州时,显示Menu()已经执行。 主计长受到压力,其工作。 但是,NOT被称作是代表的方法。

- (void)showMenu
{
    NSLog(@"show menu");
    [self.delegate pushMapviewRight];
}

但没有发生。 什么是错误的? 非常感谢帮助!

最佳回答

I fixed it. At first I used NSLog to verify that self was not nil (which is pretty obvious , but still) I m actually not sure why, but self.mapviewController.rootviewController = self; did not "carry over" to the point where I wanted to reference self.rootViewController, although self was not nil at the point where I set it to be the pointer to rootViewController.

我通过创建另一个<代码>initWithRootViewController(UCRootViewController*) ctrl

难道有人可以解释为什么在《马普托意见》中没有有效提及自称(=rootViewController)。

问题回答

<代码>意见交换器 财产是有力的参照物还是软弱? 这可能是强有力的。 如果对物体的提及不甚微,则立即予以公布,在标的放行时,参考材料薄弱。 您在申请放弃物体时,需要一个强有力的参考。

正如@CodaFi所说,你的代码看上去了不起。 为什么你在UCMapViewController上设定了代表财产价值? 代表应放在其父母身边,当其住家或为之做准备时。

Basically, if your UCMapViewController has knowledge about UCRootViewController implementing a delegate method, why not call its method from riitVuewController directly? No need to set delegate at all.

这里是使用故事片和血清的一个例子,UCMyViewController将把缝gue推到UCMapViewController:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  ...
  [segue.destinationViewController setDelegate:self.rootViewController];
  ...
}




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

热门标签