나는 카테고리 트리를 탐색하는 간단한 테스트 앱을 만들고있다. 나는 여러 섹션으로 테이블 뷰를 분할하려고 할 때마다, 나는 전혀 도움이 호출 스택과 SIGABRT를 얻을이 :NSRangeException을 일으키는 UITableView의 여러 섹션?
응용 프로그램을 종료로 인해 캐치되지 않는 예외 'NSRangeException'이유로 '*** - [__ NSArrayI objectAtIndex :] : 경계 1을 넘어선 인덱스 1 '
나는 모든 곳에서 중단 점을 넣었습니다. numberOfSectionsInTableView
이 1
을 반환하면 모든 것이 올바르게 작동하지만 2
을 반환하면 다른 중단 점에 도달하지 않습니다. objectAtIndex
을 호출 할 때마다 중단 점을 설정 했으므로 문제가있는 곳을 알 수 없습니다.
//
// MasterViewController.m
// Vingo
//
// Created by ryan on 12-01-23.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "MasterViewController.h"
#import "LinkViewController.h"
@implementation MasterViewController
@synthesize detailViewController = _detailViewController;
- (void)awakeFromNib
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
[super awakeFromNib];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
categories = [NSArray arrayWithObjects:[[VingoCategory alloc] initWithId:0 andName:@"A category"], nil];
links = [NSArray arrayWithObjects:[[VingoLink alloc] initWithId:0 andName:@"A link"], nil];
//links = [NSArray array]; // works
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#pragma mark - Table data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [categories count] && section == 0 ?
[categories count]
: [links count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if([categories count]) {
if([links count]) {
return 2;
}
return 1;
}
if([links count]) {
return 1;
}
return 0;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [categories count] && section == 0 ?
@"Categories"
: @"Links";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
// Try to get a reusable cell:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if([categories count] && indexPath.section == 0) {
NSLog(@"Looking for item %d in categories", indexPath.row);
VingoCategory *category = [categories objectAtIndex:indexPath.row];
cell.textLabel.text = category.name;
cell.textLabel.tag = category.id;
} else {
NSLog(@"Looking for item %d in links", indexPath.row);
VingoLink *link = [links objectAtIndex:indexPath.row];
cell.textLabel.text = link.name;
cell.textLabel.tag = link.id;
}
return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if([categories count] && indexPath.section == 0) {
} else {
LinkViewController *linkController = [[LinkViewController alloc] init];
VingoLink *link = [links objectAtIndex:indexPath.row];
linkController.navigationItem.title = link.name;
[self.navigationController pushViewController:linkController animated:YES];
}
return indexPath;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
@end
사람이 문제를 찾을 수 :
여기 내 구현 코드입니까? 나는 그것이 진실이 아닌 심각한 문제가 아니라는 것을 분명히 밝혀주고 싶다.
두 개의 동일한 NSArray
에 대한 내 초기화는 viewDidLoad
입니다.
흠 ... 나는'UITableViewDataSource'가 취급 생각? '코스, 방금 Xcode 4로 옮겼으며 새로운 것이 무엇인지 잘 모릅니다. – Ryan