gpt4 book ai didi

ios - 无法从类访问属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:54 25 4
gpt4 key购买 nike

//MigrationVC.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MigrationVC : UIViewController

@end

//MigrationVC.m
#import "MigrationVC.h"

@interface MigrationVC()
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIProgressView *progressView;

@end

@implementation MigrationVC

@end

//CoreData
#import "CoreData.h"
#import "MigrationVC.h"

@interface CoreData()
@property (nonatomic,retain) MigrationVC *migrationVC;
@end

-(void)obsererForKeyPath:(NSString*)keyPath object:(id)object change:(NSDictionary*)change context:(void*)context
{
if([keyPath isEqualToString:@"migrationProgress"])
{
dispatch_async(dispatch_get_main_queue(),^{
float progress=[[change objectForKey:NSKeyValueChangeNewKey] floatValue];
self.migrationVC.progress=progress;
});
}
}

我现在正在尝试学习 CoreData 和迁移,但这让我很头疼。

我正在尝试从其他类访问 socket 属性,但总是给出红色警告(在 MigrationVC* 类型的对象上找不到属性“标签”)。

我尝试在 .h 文件中添加一个可访问的 NSString 属性,但是当我尝试将导出从 .m 更改为 .h 文件时,我无法按住 Ctrl 键并拖动 .h 文件中的 View 。

我从来没有遇到过这个问题。我过去曾多次从 .m 文件访问导出,但它现在只给我警告。如何在 .m 文件中访问属性?

The problem is i can't add the outlet in .h file

我无法输出 .h 文件中的属性。

最佳答案

您必须将 socket 属性从 .m 文件传输到 .h 文件(复制和粘贴)。如果您希望您的属性是公开的,那么它们必须在头文件中声明。如果您希望它们是私有(private)的 - 在实现文件中声明它们。

//MigrationVC.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MigrationVC : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIProgressView *progressView;
@end

//MigrationVC.m
#import "MigrationVC.h"

@interface MigrationVC()

@end

@implementation MigrationVC

@end

关于ios - 无法从类访问属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34419807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com