Итак, у меня есть UITableView, который должен пройти через один NSMutableArray и использовать каждый из них в качестве меток строки.В настоящее время единственный способ, которым я могу заставить это работать, состоит в том, чтобы 0 или 1 строка, 2 или выше, выдает ошибку, говоря, что индекс массива выключен.Я попытался NSLog вывести мой массив и могу подтвердить, что он читает все строки.
// table methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Set up the cell...
NSString *cellValue = [harvestRecipeList objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
Код массива хранится в том же файле (MasterViewController.m), который я добавил ниже.
- (void)viewDidLoad
{
[super viewDidLoad];
harvestRecipeList = [[NSMutableArray alloc] init];
[harvestRecipeList addObject:@"Ice Cream"];
[harvestRecipeList addObject:@"Walnut Cake"];
[harvestRecipeList addObject:@"Cookies"];
[harvestRecipeList addObject:@"Salad"];
[harvestRecipeList addObject:@"Grilled Fish"];
//Set the title
self.navigationItem.title = @"BTN Recipes";
}
Я бы хотел любую помощь по этому поводу, это меня беспокоит.Я использовал [cropRecipeList count] , но это выдает ту же ошибку индекса массива.И как я уже упоминал, я могу заставить приложение работать отлично с 0 или 1 строкой - заранее спасибо за любую помощь!
РЕДАКТИРОВАТЬ: вот ошибка, которую я получаю в окне вывода после сборки:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
EDIT2 : включено ниже настройки моего свойства для HarvestRecipeList
//MasterViewController.h
@interface MasterViewController : UITableViewController {
NSMutableArray *harvestRecipeList;
}
@property (nonatomic, retain) NSMutableArray *harvestRecipeList;
// and also my MasterViewController.m
@synthesize harvestRecipeList;
EDIT3 Вот мой исходный код, сжатый для этого проекта.Он называется treehouse, пока что только для тестирования, но вы можете dl из моего облачного приложения здесь .