iphone - 无法访问另一个类的@property

标签 iphone objective-c ios cocoa-touch

这里是一个非常菜鸟的问题。
我有 2 个 VC。
一个叫 SGPlayer另一个是 SGDownloader .基本上我想改变 SGDownloader 的属性从第一个类开始。
我导入 SGDownloader像这样的类:

//  SGPlayer.h

#import <UIKit/UIKit.h>
#import "SGDownloader.h"

@interface SGPlayer : UIViewController

@property (nonatomic, retain) SGDownloader *downloaderClass;
SGPlayer.m是这样的:
//  SGPlayer.m

#import "SGPlayer.h"

@interface SGPlayer ()

@end

@implementation SGPlayer
@synthesize downloaderClass;

然后我将 downloadUrl 属性设置为 SGDownloaderUIButton 触发的操作中的类像那样:
- (IBAction)loadURLButton:(id)sender {

    [self performSegueWithIdentifier:@"loadMyData" sender:nil];
    downloaderClass.downloadURL = [NSURL URLWithString:@"http://www.google.com"];
}
NSLog在我的 URL 上给我 (null)。如果我使用 prepareForSegue方法一切都很好:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"loadMyData"])
    {
        SGDownloader *vc = [segue destinationViewController];

        vc.downloadURL = [NSURL URLWithString:@"http://www.google.com"];
    }
}

问题是我不想使用 prepareForSegue这里。

我想我可能误解了如何在 Obj-C 中的类之间传输数据的整个概念。

编辑:

我在 SGDownloader 中确实有一个综合属性类(class):
@interface SGDownloader : UIViewController

@property (nonatomic, retain) NSURL *downloadURL;

@end

最佳答案

创建 downloadURL 的属性并合成它,或者您可以使用委托(delegate)在类之间传递值

关于iphone - 无法访问另一个类的@property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13947921/

相关文章:

c - 如何@synthesize C 风格的指针数组?

ios - 打开 UIViewController,不显示 UINavigationController 导航栏

javascript - window.close() 不适用于 iOS 8 GM 种子

ios - Swift 数组追加不适用于 collectionView 重新加载数据

iphone - iOS : NSDateFormatter memory leak/viewDidUnload

ios - 使用Cordova在iTunes中打开应用

iphone - '接收器(<ViewController :>) has no segue with identifier 'infoseg'

iphone - 检测 UITableView 是否处于 beginUpdates/endUpdates 状态

c++ - 当进程退出时收到通知

ios - 如何在 "MyClassName.var"之类的 objective-c 中使用类变量?