仅在弧或gc模式下允许合成弱性质

Nik*_*Nik 13 objective-c ios

嘿,我今天刚开始ios编程,我正面临着这个错误.

PLZ帮我删除此错误

PLZ建议我一些不错的ios开发人员教程

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *txtUsername;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)loginClicked:(id)sender;
- (IBAction)backgroundClick:(id)sender;


@end
Run Code Online (Sandbox Code Playgroud)

Rob*_*Rob 20

如果您不使用ARC,则无法使用weak.对于IBOutlet非ARC代码引用,更换你的引用weakretain,来代替.(这有点令人困惑,但通常你使用assign而不weak是非ARC代码,但对于IBOutlet引用,你使用retain.)

更好的是,正如nneonneo所说,你应该使用ARC.


nne*_*neo 9

如果你刚刚开始,你应该只启用ARC.它会为您节省很多麻烦,它将解决这个问题.

  • 其他人会争辩说刚开始的人应该禁用ARC,这样他们就可以更好地学习和理解内存管理.使用ARC要容易得多,但是你不知道发生了什么.对于使用IB而不是在代码中执行UI,可以进行相同的论证.IB使一些事情变得更容易,但是当它不起作用时,你不知道该怎么做. (3认同)
  • @rmaddy:我同意你的观点,IT(新手)中的人和新人选择更简单的解决方案而不是复杂的解决方案.这是一个广泛的讨论话题.没有人可以在这个话题中获胜. (3认同)