Мое приложение падает, когда я прокручиваю свой TableView.Сначала в моем методе viewDidLoad загружается словарь из файла, и для этого словаря я перечисляю все ключи.
- (void)viewDidLoad {
[super viewDidLoad];
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
path = [rootPath stringByAppendingPathComponent:[NSString stringWithFormat:@"currency.archive"]];
banks = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
keys = [banks allKeys];
// set date for last update
dayMonthYear.text = [banks objectForKey:@"Last Updated"];
}
В моем cellForRowAtIndexPath я заполняю ячейки данными из этого словаря.В любом случае, когда мое приложение запускается, все выглядит нормально, первые пять строк отображаются правильно, но когда я начинаю прокручивать мое приложение, происходит сбой.Моя идея заключается в том, что проблема здесь с автоматически выпущенным объектом, я пытался сохранить их и после их использования выпустить, но безуспешно.Отладчик показывает, что моя проблема в строке с жирным шрифтом
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell %d_%d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CurrencyTableCell" owner:self options:nil];
cell = currencyTableCell;
//don't show selected cell
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//set height
self.cellHeight = cell.frame.size.height;
}
// Fetch currency
NSString *currentCurrency = [keys objectAtIndex:indexPath.row];
NSDictionary *fetchedCurrency = [banks objectForKey:currentCurrency];
**NSString *name = [fetchedCurrency objectForKey:@"Currency Name"];**
currencyTitle.text = name;
NSString *charCode = [fetchedCurrency objectForKey:@"Code"];
currencyCode.text = charCode;
NSString* formattedNumber = [NSString stringWithFormat:@"%.02f",[[fetchedCurrency objectForKey:@"Value"] floatValue]];
if ([formattedNumber length] == 4) {
formattedNumber = [NSString stringWithFormat:@"%@%@",@"0",formattedNumber];
}
buyPrice.text = formattedNumber;
return cell;
}