그래서 사용자 입력에 따라 자동으로 채워지는 UItableView가 있습니다. arrColors라는 색 이름의 마스터 배열과 arrAutoCorrect라는 'temp'배열이 있는데,이 배열은 사용자가 입력 할 때 채워집니다.다른 배열로 채워진 경우에만 NSMutableArray가 범위를 벗어납니다.
두 배열 모두 NSMutableArrays입니다.
사용자가 모든 텍스트를 지우면 임시 배열이 모든 색상에서 완전히로드되어야합니다. 색상 배열에는 21 개의 색상 (문자열)이 있습니다.
색인이 17 (0 - 16) 범위를 벗어납니다.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 17 beyond bounds [0 .. 16]'
그것은 나를 미치게합니다.
이것은 17 명이 어디에서 왔습니까? 다시 오류는 사용자가 텍스트 상자의 모든 내용을 지울 때만 나타납니다.
내가 할 수있는 모든 것에 대해 NSLogged를 사용하고 있으며,이 범위 내에서 17을 호출하는 것을 찾을 수 없습니다.
내 코드
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring :(NSMutableArray*) passedArray {
[self.arrAutoComplete removeAllObjects];
if ([substring length] == 0) {
//add all items
int count = 0;
for (NSString* c in passedArray) {
NSLog(@"Count: %i", count);
[self.arrAutoComplete addObject:c];
count++;
}
} else {
//Narrow down
for(NSString *curString in passedArray) {
NSRange substringRange = [curString rangeOfString:substring options:NSCaseInsensitiveSearch];
NSLog(@"my range is %@", NSStringFromRange(substringRange));
if (substringRange.location == 0) {
[self.arrAutoComplete addObject:curString];
}
}
}
[self.autocompleteTableView reloadData];
}
#pragma mark - TABLE VIEW DELEGATES
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
//NSLog(@"Number of sections to call for autocomplete table is: 1");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// NSLog(@"Number of rows in section for autocomplete is: %lu", (long)[self.arrAutoComplete count]);
return [self.arrAutoComplete count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
//NSLog(@"Default cell delegate called");
NSUInteger section = [indexPath section];
// NSLog(@"Section: %lu", (unsigned long)section);
NSUInteger row = [indexPath row];
NSLog(@"Row : %lu", (unsigned long)row);
//NSLog(@"Cell for autocomplete called");
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
if (cell == nil) {
//NSLog(@"Cell for autocomplete was nil, createing new");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier];
}
//NSLog(@"Indes path row: %lu", indexPath.row);
cell.textLabel.text = [self.arrColors objectAtIndex:row];
//NSLog(@"Cell for autocomplete text should be: %@",[self.arrColors objectAtIndex:indexPath.row]);
return cell;
}
내 충돌 로그
2015-02-04 17:47:46.512 App[4033:1312614] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 17 beyond bounds [0 .. 16]'
*** First throw call stack:
(
0 CoreFoundation 0x00000001037c9f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010310bbb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001036c201e -[__NSArrayI objectAtIndex:] + 190
3 UIKit 0x0000000104193856 -[UITableViewDataSource tableView:heightForRowAtIndexPath:] + 109
4 UIKit 0x0000000103ec726b __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 302
5 UIKit 0x0000000103ec68fe -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 4125
6 UIKit 0x0000000103eca098 -[UITableViewRowData numberOfRows] + 97
7 UIKit 0x0000000103d328fc -[UITableView noteNumberOfRowsChanged] + 133
8 UIKit 0x0000000103d3203d -[UITableView reloadData] + 1316
추가 정보 : 난 후, 문자열의 길이가 0 모든 색상 searchAutocompleteEntriesWithSubstring
의 추가 주석 경우 앱이 충돌하지 않습니다.
NSLOG 문에서도
2015-02-04 17:54:19.155 Tops[4065:1359488] Number of sections to call for autocomplete table is: 1
2015-02-04 17:54:19.155 Tops[4065:1359488] Number of rows in section for autocomplete is: 3
2015-02-04 17:54:19.156 Tops[4065:1359488] Default cell delegate called
2015-02-04 17:54:19.156 Tops[4065:1359488] Section: 0
2015-02-04 17:54:19.156 Tops[4065:1359488] Row : 0
2015-02-04 17:54:19.157 Tops[4065:1359488] Default cell delegate called
2015-02-04 17:54:19.157 Tops[4065:1359488] Section: 0
2015-02-04 17:54:19.157 Tops[4065:1359488] Row : 1
2015-02-04 17:54:19.158 Tops[4065:1359488] Default cell delegate called
2015-02-04 17:54:19.158 Tops[4065:1359488] Section: 0
2015-02-04 17:54:19.158 Tops[4065:1359488] Row : 2
2015-02-04 17:54:19.612 Tops[4065:1359488] Substring:
2015-02-04 17:54:19.612 Tops[4065:1359488] Count: 0
2015-02-04 17:54:19.612 Tops[4065:1359488] Count: 1
//Removed for brevity
2015-02-04 17:54:19.617 Tops[4065:1359488] Count: 19
2015-02-04 17:54:19.617 Tops[4065:1359488] Count: 20
2015-02-04 17:54:19.617 Tops[4065:1359488] Number of sections to call for autocomplete table is: 1
2015-02-04 17:54:19.618 Tops[4065:1359488] Number of rows in section for autocomplete is: 21
2015-02-04 17:54:19.622 Tops[4065:1359488] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 17 beyond bounds [0 .. 16]'
UPDATE 나는 방법을 실종됐다
를 해결 :
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60.0f;//some random number
}
는 꼬마를 사용자의 설명서를 읽어주십시오.
NSLog의 출력을 게시 할 수 있습니까? 예외는 배열에 17 개의 객체가 있고 18 번째 (배열 17은 0부터 시작하기 때문에 색인 17)에 액세스하려고한다는 것을 나타냅니다. 충돌이 어느 선에 있습니까? – NobodyNada
searchAutocompleteEntriesWithSubstring 메서드에는 passedArray에 21 개의 개체가 있습니다. 전달 된 배열은 arrColors –
입니다. 충돌이 발생한 행은 무엇입니까? – NobodyNada