2012-01-16 14 views
0

2つの別々の(別に入力された)NSArraysの2つのビューがあるアプリがあります。 array1には10個の "ABC"オブジェクトがあり、array2には18個の "ABC"オブジェクトがあります。配列1のview1は完全に正常にロードされます。ただし、view2がクラッシュします。私はarray2の@ "ABC"項目の量をデバッグする試行錯誤の一種として変更しました。私はたった15個の "ABC"オブジェクトしか持てません。私は16番目の "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またはそれ以上を追加すると、それがクラッシュします。あなたの質問から

+0

_Onceする必要があり、アプリがクラッシュする** ** ._ のviewDidLoadについて何かを言ってより多くの情報を提供してください。 「Something」は非常に曖昧で問題を絞り込むのに役立たない。実際のエラーメッセージを投稿することが推奨されます。 – aqua

+0

Sooo ... NSMutableArrayに変更しました。 viewDidLoad { array2 = [[NSMutableArray alloc] init]; [状況addObject:@ "ABC1"]; [状況addObject:@ "ABC2"]; [状況addObject:@ "ABC3"]; ---- [状況addObject:@ "ABC18"]; }とは(のUITableViewCell *)のtableViewに以下の変更を行った:(のUITableView *)のtableView cellForRowAtIndexPath:(NSIndexPath *)indexPath: NSStringの* cellValue = [objectAtIndex配列2:indexPath.row]。 \t cell.textLabel.text = cellValue; 結果?魅力的な作品! – Jon

+0

@ジョン、答えとしてそれを追加し、できるだけそれを受け入れる。 –

答えて

0

array2 = [[NSArray alloc] initWithObjects:@"ABC1", @"ABC2", @"ABC3", @"ABC4", @"ABC5", @"ABC6", @"ABC7", @"ABC8", @"ABC9", @"ABC10", @"ABC11", @"ABC12", @"ABC13", @"ABC14", @"ABC15", ABC16", @"ABC17",@"ABC18",nil]; 

NSArraysはオブジェクトだけではなく、原始的なCタイプを含めることができます。あなたの16番目の要素、ABC16"は、配列2の初期化とアプリケーションのクラッシュの際にプリミティブとして読み込まれています。

ABC16"は、私が "ABC" @第十六を追加@"ABC16"

関連する問題