2012-01-16 44 views
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號或更多的,它崩潰。

+0

_once我添加了第十六@ 「ABC」,應用程序崩潰**說着有關的viewDidLoad ** ._ 請提供更多的信息。 「某事」非常模糊,並不能縮小問題的範圍。發佈實際的錯誤消息是首選。 – aqua 2012-01-16 22:24:20

+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 = [數組2 objectAtIndex:indexPath.row]; \t cell.textLabel.text = cellValue; 結果?奇蹟般有效!! – Jon 2012-01-16 22:41:38

+0

@Jon,補充說,作爲答案,並接受它,一旦你能夠。 – 2012-01-17 17:41:07

回答

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"在array2初始化過程中正在被讀入爲原語,並導致應用程序崩潰。

ABC16"應該@"ABC16"