UISplitViewController与故事板

时间:2011-10-31 07:03:12

标签: iphone ios ios5 iphone-4

我正在使用带有拆分视图控制器的故事板用于iPad应用程序。并将其初始设置为拆分视图控制器。我通过数组填充主视图控制器。 'feature'是NSObject类,我声明方法:

- (feature *)initWithName:(NSString *)name iconName:(NSString *)iconName featuresofiphone:(iphoneFeatures)featuresofiphone;
并在.m类中定义返回名称,iconName,NSString类型的featuresofiPhone。 这是我在didFinishLaunchingWithOptions的代码:

NSMutableArray *monsters = [NSMutableArray array];
[monsters  addObject:[[[feature alloc] initWithName:@"iphone3g" 
iconName:@"iphone3g.jpg" featuresofiphone:iphone3gf] autorelease]];

[monsters addObject:[[[feature alloc] initWithName:@"iphone3gs"  
iconName:@"iphone3gs.jpg" featuresofiphone:iphone3gsf] autorelease]];

[monsters addObject:[[[feature alloc] initWithName:@"iphone4g"  iconName:@"iphone4g.jpg"  
featuresofiphone:iphone4gf] autorelease]];

 MasterViewController *masterDetailViewController = [[MasterViewController alloc]init];
masterDetailViewController.iphones  = iphonesarray;

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
return YES;

但它在主视图控制器中给出例外:

 exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: row (0) beyond bounds (0) for section (0).'

-(void)viewDidLoad
{
  [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
 self.detailViewController = (DetailViewController *) 
 [[self.splitViewController.viewControllers lastObject] topViewController];
 [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] 
 animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}

并且控制也没有达到cellForRowAtIndexPath - 方法。帮助我!!

1 个答案:

答案 0 :(得分:0)

您没有足够的单元格,只需注释该行

即可
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];

它正在尝试滚动到不存在的单元格。

相关问题