我對iOS平臺相當陌生,並且在內存管理方面遇到了一些問題。我通過一個自定義的UIViewController類的初始化程序傳入一個對象(試用版),當UIViewController最終收到它時,該對象爲零。我希望有人能夠指引我走向正確的方向。我已經在下面列出了一些源代碼。iOS初始化參數爲零
Trial.h
@interface Trial : NSObject {
NSString *IRBNumber;
NSString *PI;
NSString *Sponsor;
NSString *ContactName;
NSString *ContactPhone;
NSString *ContactEmail;
NSString *Location;
NSString *Objective;
NSString *Eligibility;
NSString *Name;
NSString *DiseaseGroup;
NSString *Age;
}
@property (retain, nonatomic) NSString *IRBNumber;
@property (retain, nonatomic) NSString *PI;
@property (retain, nonatomic) NSString *Sponsor;
@property (retain, nonatomic) NSString *ContactName;
@property (retain, nonatomic) NSString *ContactEmail;
@property (retain, nonatomic) NSString *ContactPhone;
@property (retain, nonatomic) NSString *Location;
@property (retain, nonatomic) NSString *Objective;
@property (retain, nonatomic) NSString *Eligibility;
@property (retain, nonatomic) NSString *Name;
@property (retain, nonatomic) NSString *DiseaseGroup;
@property (retain, nonatomic) NSString *Age;
@end
DiseaseControllersViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Trial *trial = (Trial *)[dataArray objectAtIndex:indexPath.row];
TrialDetailController *detailViewController = [[TrialDetailController alloc] initWithNibNameAndTrial:@"TrialDetailController" bundle:nil trial:trial];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
[trial release];
}
這裏的初始化
-(id)initWithNibNameAndTrial: (NSString*)NibNameOrNil bundle:(NSBundle*)nibBundlerOrNil trial:(Trial *)inTrial {
self = [super initWithNibName:NibNameOrNil bundle:nibBundlerOrNil];
if(self) {
self.trial = inTrial;
}
return self;
}
TrialDetailController.h
#import "Trial.h"
@interface TrialDetailController : UITabBarController {
Trial *trial;
}
@property (nonatomic, retain) Trial *trial;
-(id)initWithNibNameAndTrial: (NSString*)NibNameOrNil bundle:(NSBundle*)nibBundlerOrNil trial:(Trial *)inTrial;
-(IBAction)objectiveTabItemClick:(id)sender;
-(IBAction)detailsTabItemClick:(id)sender;
@end
的定義
你可以發佈TrialDetailController的init-Method的代碼嗎? – samsam
你明白了。我剛剛發佈了它。 – Hopdizzle
你試過調試過嗎?您可以在gdb調試器(控制檯窗口)中設置斷點並查看變量/屬性值。請參閱[XCode4中的Objective-C調試技巧?](http://stackoverflow.com/a/7650979/590956)。只是想知道'po dataArray'會在調試器中顯示什麼。你在哪裏添加值到這個數組中,並且在你嘗試向它添加對象之前初始化數組? – Sam