所以我創建的NSObject的子類,稱爲Query
如何使用NSObject子類?
@interface Query : NSObject
@property (nonatomic, assign) NSNumber *weight;
@property (nonatomic, assign) NSNumber *bodyFat;
@property (nonatomic, assign) NSNumber *activityLevel;
@end
這是正確的設置對象的屬性?
在VC1:
BodyFatViewController *aViewController = [[BodyFatViewController alloc]init];
aViewController.query = self.query;
[self.navigationController pushViewController:aViewController animated:YES];
在VC2:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
Query *anQuery = [[Query alloc]init];
anQuery.bodyFat = [self.bodyFatArray objectAtIndex:row];
anQuery.weight = self.query.weight;
self.query = anQuery;
}
我假設你的init方法編碼根據模板,通過調用super.init和自我的分配,對不對? – dasblinkenlight 2012-04-07 23:16:08
我還沒有爲'Query'對象添加一個init方法。任何一個VC的'init'方法都不會執行超級調用的任何操作。 – Jon 2012-04-07 23:30:30
你應該那麼好。 – dasblinkenlight 2012-04-07 23:32:03