0
我有一个应用程序有两个单独的视图与两个单独(并单独填充)NSArrays
。在array1中,我有10个“ABC”对象,而在array2中,我有18个“ABC”对象。 view1与array1加载完全正常;然而,view2崩溃。我改变了array2中@“ABC”项的数量,作为一种反复试验的方式进行调试,发现我只能拥有15个“ABC”对象。一旦我添加第十六个“ABC”,该应用程序崩溃说一些关于viewDidLoad
。有谁知道如何解决这个问题或我正在做什么会导致应用程序崩溃?NSArray造成viewDidLoad崩溃
- (void)viewDidLoad {
array2 = [[NSArray alloc] initWithObjects:@"ABC1", @"ABC2", @"ABC3", @"ABC4", @"ABC5", @"ABC6", @"ABC7", @"ABC8", @"ABC9", @"ABC10", @"ABC11", @"ABC12", @"ABC13", @"ABC14", @"ABC15", ABC16", @"ABC17",@"ABC18",nil];
[super viewDidLoad];
}
(#pragma mark Table view methods)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [array2 count];
}
// Customize the appearance of table view cells.
- (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];
}
// Set up the cell...
cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor redColor];
return cell;
}
就像我说的,数组2可与15个或更少的对象完全没有问题,但一旦我加16号或更多的,它崩溃。
_once我添加了第十六@ “ABC”,应用程序崩溃**说着有关的viewDidLoad ** ._ 请提供更多的信息。 “某事”非常模糊,并不能缩小问题的范围。发布实际的错误消息是首选。 – aqua 2012-01-16 22:24:20
Sooo ...我将它切换到如下这样的NSMutableArray: viewDidLoad { array2 = [[NSMutableArray alloc] init]; [情况addObject:@“ABC1”]; [情况addObject:@“ABC2”]; [情况addObject:@“ABC3”]; ---- [情况addObject:@“ABC18”]; } 和由在(的UITableViewCell *)的tableView下列变化:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath: 的NSString * cellValue = [数组2 objectAtIndex:indexPath.row]; \t cell.textLabel.text = cellValue; 结果?奇迹般有效!! – Jon 2012-01-16 22:41:38
@Jon,补充说,作为答案,并接受它,一旦你能够。 – 2012-01-17 17:41:07