【发布时间】:2013-02-19 23:11:11
【问题描述】:
我正在尝试做一个pickerView,但我的访问权限很差:
这是我的代码
-(void) viewWillAppear:(BOOL)animated {
list = [[NSArray alloc]init];
[self populateList]
}
-(void) populateList {
NSString *path = [[NSBundle mainBundle] pathForResource:@"nameoffile" ofType:@"txt"];
NSString *file = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
list = [file componentsSeparatedByString:@"\n"];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return (NSString *)[list objectAtIndex:row]; //here I'm getting bad acces
}
错误是:“线程1:EXC_BAD_ACCESS(code=1, address=0xa001cc65)”
【问题讨论】:
-
请发布崩溃的(符号)堆栈跟踪。
-
OK 在出现错误的行之前添加:
NSAssert(row < [list count], @"Row %d is out-of-range", row);并重新运行您的应用。 -
@trojanfoe 帮不上什么忙。这是一个段错误,而不是 NSException。
-
@H2CO3 是的,但您应该能够使用
bt从 lldb 获取堆栈跟踪? -
@illDev: 你确定 pickerView:titleForRow 只有在列表被填充后才会被调用吗?
标签: objective-c ios4