Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

luke3

macrumors newbie
Original poster
Jun 6, 2012
23
0
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;
    }
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,561
6,059
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...
 

luke3

macrumors newbie
Original poster
Jun 6, 2012
23
0
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...

Yeah the crash is happening on


Player *p = [_fetchedResultsController objectAtIndexPath: indexPath];
 

KnightWRX

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
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]

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 ?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.