我已经坚持了好几天了,每次我回到它时,我都会让我的代码越来越让自己感到困惑,哈哈。这就是我想要做的。我有收费的表格列表,我点击一个并显示一个包含收费详细信息的模型视图。现在,当模型出现时,会创建一个对象来获取用户的 XML 列表并对其进行解析并通过自定义委托返回 NSMutableArray。然后我有一个按钮,它显示一个选择器弹出框,当调用弹出框视图时,用户数组在对弹出框视图的 initWithArray 调用中使用。我知道数组中的数据是正确的,但是当调用 [pickerUsers count] 时,我得到一个 EXC_BAD_ACCESS。我认为这是一个内存/所有权问题,但似乎没有任何帮助。任何帮助,将不胜感激。
相关代码片段:
Charge Popover(充电细节模型视图):
@interface ChargePopoverViewController .....
NSMutableArray *pickerUserList;
@property (nonatomic, retain) NSMutableArray *pickerUserList;
@implementation ChargePopoverViewController
@synthesize whoOwesPickerButton, pickerUserList;
- (void)viewDidLoad {
JEHWebAPIPickerUsers *fetcher = [[JEHWebAPIPickerUsers alloc] init];
fetcher.delegate = self;
[fetcher fetchUsers];
}
-(void) JEHWebAPIFetchedUsers:(NSMutableArray *)theData {
[pickerUserList release];
pickerUserList = theData;
}
- (void) pickWhoPaid: (id) sender {
UserPickerViewController* content = [[UserPickerViewController alloc] initWithArray:pickerUserList];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:content];
[popover presentPopoverFromRect:whoPaidPickerButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
content.delegate = self;
}
用户选择器视图控制器
@interface UserPickerViewController .....
NSMutableArray *pickerUsers;
@property(nonatomic, retain) NSMutableArray *pickerUsers;
@implementation UserPickerViewController
@synthesize pickerUsers;
-(UserPickerViewController*) initWithArray:(NSMutableArray *)theUsers {
self = [super init];
if ( self ) {
self.pickerUsers = theUsers;
}
return self;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
// Dies Here EXC_BAD_ACCESS, but NSLog(@"The content of array is%@",pickerUsers); shows correct array data
return [pickerUsers count];
}
如果可能有帮助,我可以提供其他代码。提前致谢。