我开始在iOS开发中。我一直在寻找解决方案好几天,我无法得到它。我得到了以下代码:
@interface SAProfileViewController : UITableViewController {
@public NSNumber *userId;
}
@property (weak, nonatomic) IBOutlet UIView *awesomeProfileHeader;
@property (nonatomic, assign) NSNumber *userId;
@end
正如你所看到我宣布我的财产,然后我这样做:
@implementation SAProfileViewController
@synthesize userId = _userId;
...
在另一个ViewController上,我导入了SAProfileViewController。
#import "SAProfileViewController.h"
...
-(void)goToUserProfile :(id) sender
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
SAProfileViewController *controller = [[SAProfileViewController alloc] init];
controller.userId = gesture.view.tag; // << HERE THE ERROR APPEARS
[self.navigationController pushViewController:controller animated:YES];
}
就是这样,这是我的代码,我收到以下错误: “在'SAProfileViewController *'
类型的对象上找不到”属性'userId'提前致谢。
答案 0 :(得分:2)
您在使用属性类型时遇到了错误。
更改
@property (nonatomic, assign) NSNumber *userId;
到
@property (nonatomic, retain) NSNumber *userId;
您必须像这样创建NSNumber
gesture.view.tag
个实例
controller.userId = [NSNumber numberWithInteger:gesture.view.tag];
或者您可以将userId更改为NSInteger
而不是NSNumber*
@property (nonatomic, assign) NSInteger userId;
(你必须为对象属性userId
执行此操作)