这是我的代码:
secondClass.h
@property (nonatomic) int number;
secondClass.m
@synthesize number;
//positioning object in x position of first class
object.center = CGPointMake(number, object.center.y);
NSLog(@"%d",number);
first class.m
#import "secondClass.h"
secondClass *second = [secondClass alloc];
second.number = 15;
我用NSLog来看看发生了什么。在第一个类中,第二个数字的值是15.当我使用NSLog在第二个类中看到它的值时,它变为0。
我做错了什么?
答案 0 :(得分:0)
也许你的描述中只有一个拼写错误,但请尝试:
secondClass *second = [[secondClass alloc] init];
second.number = 15;
NSlog(@"number is:%d",number);
答案 1 :(得分:0)
尝试在secondClass.m中合成您的号码
@synthesize number;
并在secondClass声明中添加 init
希望这有帮助。答案 2 :(得分:0)
找一个类似的案例。问题在于我使用segue从一个视图控制器转换到另一个视图控制器。我用方法prepareForSegue解决了问题。这是我正在搜索的代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"NextView"]){
secondClass *second = (secondClass *)segue.destinationViewController;
second.number = object.center.x;
}
}
答案 3 :(得分:0)
@property (readwrite) int number;
//第一堂课
second *move = [[second alloc] initWithNibName:@"second" bundle:nil];
move.number = 15;
[self.navigationController pushViewController:move animated:YES];
[move release];