index 1 beyond bounds [0 .. 0] Core Data

Discussion in 'iOS Programming' started by luke3, Jul 6, 2012.

  1. luke3 macrumors newbie

    Joined:
    Jun 6, 2012
    #1
    I am using core data to fetch an entity. I only want those results to show up in the second section of my tableview and something else show up in another section... But I am getting the crash. What am I doing wrong?

    index 1 beyond bounds [0 .. 0]

    Here is some code
    Code:
     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch(section){
            case 0:
                return 7;
            case 1:
            return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
    
        }
        return 0;
        }
    
        - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 2;
        }
    
        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
    
        Player *p = [_fetchedResultsController objectAtIndexPath: indexPath];
    
            switch (indexPath.section) {
            case 0:
                switch (indexPath.row) {
                    case 0:
                        cell.textLabel.text = _team.teamName;
                        break;
                    case 1:
                        cell.textLabel.text = _team.headCoach;
                        break;
                    default:
                        break;
                }
                break;
            case 1:{
    
                cell.textLabel.text = p.firstName;
                cell.detailTextLabel.text = p.team.teamName;
            }
            default:
            break;
        }
    
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Have you identified the line that is causing the crash? I'm on a mobile so I don't have any debug tools with me but nothing is jumping out at me...
     
  3. luke3 thread starter macrumors newbie

    Joined:
    Jun 6, 2012
    #3
    Yeah the crash is happening on


    Player *p = [_fetchedResultsController objectAtIndexPath: indexPath];
     
  4. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #4
    Well, seems your array contains 0 or 1 entries and you're trying to fetch the 2nd entry. Use a watch on the variable in the debugger to see its content.

    Particular reason you're using _fetchedResultsController instead of self.fetchedResultsController ?
     

Share This Page