【发布时间】:2013-01-19 13:21:24
【问题描述】:
我是 iOS 开发新手。
我有一个类叫宠物
@interface Pet : NSObject
@property(nonatomic, strong) NSString *petName;
@property(nonatomic, strong) NSString *petBreed;
@end
在我的一种方法中,我试图为 Pet 类型的已声明对象设置值:
Pet *selectedPet;
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
NSString *currentPetTemp,*currentBreedTemp;
currentPetTemp = cell.textLabel.text;
currentBreedTemp = cell.detailTextLabel.text;
selectedPet.petName = currentPetTemp;
selectedPet.petBreed = currentBreedTemp;
NSLog(@"%@ Name1: %@",selectedPet.petName,currentPetTemp);
return indexPath;
}
NSLog 显示“currentPetTemp”的正确值,但 selectedPet.petName 显示“null”。
任何帮助将不胜感激。
【问题讨论】:
标签: iphone ios objective-c