奇怪的NSOrderedSet行为

时间:2013-11-25 04:44:45

标签: ios objective-c

我有这个代码,应该正确设置包含日历事件的表格视图:

...

#pragma mark - UITableView Delegate and DataSource methods

- (int)numberOfSectionsInTableView:(UITableView *)tableView {

    ...

    NSLog(@"TEST %d", self.user.calendarDays.count);
    NSLog(@"TEST %@", [self.user.calendarDays objectAtIndex:3]);
    return self.user.calendarDays.count;

    ...

}

...    

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }

    ...

    NSOrderedSet *calendarDays = self.user.calendarDays;
    NSLog(@"CalendarDays: [%@]", calendarDays);
    CalendarDay *calendarDay = [calendarDays objectAtIndex:indexPath.section];
    NSLog(@"CalendarDay: [%@]", calendarDay);
    cell.textLabel.text = [[[calendarDay calendarEvents] objectAtIndex:indexPath.row] title];

    ...

    return cell;
}

...

然而,应用程序每次都会在CalendarDay *calendarDay = [calendarDays objectAtIndex:indexPath.section];行崩溃。输出(包括NSLogs):

2013-11-25 13:05:34.731 Nobles[9176:60b] TEST 4
2013-11-25 13:05:34.734 Nobles[9176:60b] TEST <CalendarDay: 0x155a3960> (entity: CalendarDay; id: 0x155a2f50 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/CalendarDay/p26> ; data: <fault>)
2013-11-25 13:05:35.280 Nobles[9176:60b] CalendarDays: [Relationship 'calendarDays' on managed object (0x155616e0) <User: 0x155616e0> (entity: User; id: 0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1> ; data: {
    assemblySeat = "";
    calendarDays =     (
        "0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3>",
        "0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5>",
        "0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7>"
    );
    correctPIN = 1;
    cubby = 1;
    faculty = 0;
    homeSportEvents = "<relationship fault: 0x155ae7d0 'homeSportEvents'>";
    lockerCombo = "";
    lockerNum = "";
    macLockerCombo = "3-29-35";
    macLockerNum = 133;
    menuBackground = 0;
    mySportEvents = "<relationship fault: 0x155ae820 'mySportEvents'>";
    name = Carlo;
    parent = 0;
    peopleID = 21894;
    pin = cabelli16;
    proPic = <ffd8ffe0 00104a46 49460001 000100fa 00fa0000 fffe001f 4c454144 20546563 686e6f6c 6f676965 7320496e 632e2056 312e>;
    reservations = "<relationship fault: 0x155ae860 'reservations'>";
    resultSportEvents = "<relationship fault: 0x155ae8a0 'resultSportEvents'>";
    scheduleDays = "<relationship fault: 0x155ae8e0 'scheduleDays'>";
    student = 1;
    unid = cabelli16;
}) with objects {(
    <CalendarDay: 0x1567ab70> (entity: CalendarDay; id: 0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3> ; data: {
    calendarEvents =     (
        "0x155b1820 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A2>"
    );
    dateString = "11/16/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x15683c80> (entity: CalendarDay; id: 0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5> ; data: {
    calendarEvents =     (
        "0x15683940 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A4>"
    );
    dateString = "11/17/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x156842d0> (entity: CalendarDay; id: 0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7> ; data: {
    calendarEvents =     (
        "0x15684150 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A6>"
    );
    dateString = "11/18/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})
)}]
2013-11-25 13:05:48.933 Nobles[9176:60b] CalendarDay: [<CalendarDay: 0x1567ab70> (entity: CalendarDay; id: 0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3> ; data: {
    calendarEvents =     (
        "0x155b1820 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A2>"
    );
    dateString = "11/16/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})]
2013-11-25 13:05:48.940 Nobles[9176:60b] CalendarDays: [Relationship 'calendarDays' on managed object (0x155616e0) <User: 0x155616e0> (entity: User; id: 0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1> ; data: {
    assemblySeat = "";
    calendarDays =     (
        "0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3>",
        "0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5>",
        "0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7>"
    );
    correctPIN = 1;
    cubby = 1;
    faculty = 0;
    homeSportEvents = "<relationship fault: 0x155ae7d0 'homeSportEvents'>";
    lockerCombo = "";
    lockerNum = "";
    macLockerCombo = "3-29-35";
    macLockerNum = 133;
    menuBackground = 0;
    mySportEvents = "<relationship fault: 0x155ae820 'mySportEvents'>";
    name = Carlo;
    parent = 0;
    peopleID = 21894;
    pin = cabelli16;
    proPic = <ffd8ffe0 00104a46 49460001 000100fa 00fa0000 fffe001f 4c454144 20546563 686e6f6c 6f676965 7320496e 632e2056 312e>;
    reservations = "<relationship fault: 0x155ae860 'reservations'>";
    resultSportEvents = "<relationship fault: 0x155ae8a0 'resultSportEvents'>";
    scheduleDays = "<relationship fault: 0x155ae8e0 'scheduleDays'>";
    student = 1;
    unid = cabelli16;
}) with objects {(
    <CalendarDay: 0x1567ab70> (entity: CalendarDay; id: 0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3> ; data: {
    calendarEvents =     (
        "0x155b1820 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A2>"
    );
    dateString = "11/16/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x15683c80> (entity: CalendarDay; id: 0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5> ; data: {
    calendarEvents =     (
        "0x15683940 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A4>"

    );
    dateString = "11/17/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x156842d0> (entity: CalendarDay; id: 0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7> ; data: {
    calendarEvents =     (
        "0x15684150 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A6>"
    );
    dateString = "11/18/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})
)}]
2013-11-25 13:05:50.116 Nobles[9176:60b] CalendarDay: [<CalendarDay: 0x15683c80> (entity: CalendarDay; id: 0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5> ; data: {
    calendarEvents =     (
        "0x15683940 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A4>"
    );
    dateString = "11/17/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})]
2013-11-25 13:05:50.122 Nobles[9176:60b] CalendarDays: [Relationship 'calendarDays' on managed object (0x155616e0) <User: 0x155616e0> (entity: User; id: 0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1> ; data: {
    assemblySeat = "";
    calendarDays =     (
        "0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3>",
        "0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5>",
        "0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7>"
    );
    correctPIN = 1;
    cubby = 1;
    faculty = 0;
    homeSportEvents = "<relationship fault: 0x155ae7d0 'homeSportEvents'>";
    lockerCombo = "";
    lockerNum = "";
    macLockerCombo = "3-29-35";
    macLockerNum = 133;
    menuBackground = 0;
    mySportEvents = "<relationship fault: 0x155ae820 'mySportEvents'>";
    name = Carlo;
    parent = 0;
    peopleID = 21894;
    pin = cabelli16;
    proPic = <ffd8ffe0 00104a46 49460001 000100fa 00fa0000 fffe001f 4c454144 20546563 686e6f6c 6f676965 7320496e 632e2056 312e>;
    reservations = "<relationship fault: 0x155ae860 'reservations'>";
    resultSportEvents = "<relationship fault: 0x155ae8a0 'resultSportEvents'>";
    scheduleDays = "<relationship fault: 0x155ae8e0 'scheduleDays'>";
    student = 1;
    unid = cabelli16;
}) with objects {(
    <CalendarDay: 0x1567ab70> (entity: CalendarDay; id: 0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3> ; data: {
    calendarEvents =     (
        "0x155b1820 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A2>"
    );
    dateString = "11/16/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x15683c80> (entity: CalendarDay; id: 0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5> ; data: {
    calendarEvents =     (
        "0x15683940 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A4>"
    );
    dateString = "11/17/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x156842d0> (entity: CalendarDay; id: 0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7> ; data: {
    calendarEvents =     (
        "0x15684150 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A6>"
    );
    dateString = "11/18/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})
)}]
2013-11-25 13:05:51.548 Nobles[9176:60b] CalendarDay: [<CalendarDay: 0x156842d0> (entity: CalendarDay; id: 0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7> ; data: {
    calendarEvents =     (
        "0x15684150 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A6>"
    );
    dateString = "11/18/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})]
2013-11-25 13:05:51.553 Nobles[9176:60b] CalendarDays: [Relationship 'calendarDays' on managed object (0x155616e0) <User: 0x155616e0> (entity: User; id: 0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1> ; data: {
    assemblySeat = "";
    calendarDays =     (
        "0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3>",
        "0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5>",
        "0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7>"
    );
    correctPIN = 1;
    cubby = 1;
    faculty = 0;
    homeSportEvents = "<relationship fault: 0x155ae7d0 'homeSportEvents'>";
    lockerCombo = "";
    lockerNum = "";
    macLockerCombo = "3-29-35";
    macLockerNum = 133;
    menuBackground = 0;
    mySportEvents = "<relationship fault: 0x155ae820 'mySportEvents'>";
    name = Carlo;
    parent = 0;
    peopleID = 21894;
    pin = cabelli16;
    proPic = <ffd8ffe0 00104a46 49460001 000100fa 00fa0000 fffe001f 4c454144 20546563 686e6f6c 6f676965 7320496e 632e2056 312e>;
    reservations = "<relationship fault: 0x155ae860 'reservations'>";
    resultSportEvents = "<relationship fault: 0x155ae8a0 'resultSportEvents'>";
    scheduleDays = "<relationship fault: 0x155ae8e0 'scheduleDays'>";
    student = 1;
    unid = cabelli16;
}) with objects {(
    <CalendarDay: 0x1567ab70> (entity: CalendarDay; id: 0x1567ade0 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A3> ; data: {
    calendarEvents =     (
        "0x155b1820 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A2>"
    );
    dateString = "11/16/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x15683c80> (entity: CalendarDay; id: 0x15683d00 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A5> ; data: {
    calendarEvents =     (
        "0x15683940 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A4>"

    );
    dateString = "11/17/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
}),
    <CalendarDay: 0x156842d0> (entity: CalendarDay; id: 0x15684470 <x-coredata:///CalendarDay/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A7> ; data: {
    calendarEvents =     (
        "0x15684150 <x-coredata:///CalendarEvent/t2757F3FB-BC75-435C-B0A4-FDA936D3E91A6>"
    );
    dateString = "11/18/2013";
    user = "0x1554ad10 <x-coredata://FA2FBE99-00BF-4603-8479-9DAC1881AAC6/User/p1>";
})
)}]
2013-11-25 13:05:53.801 Nobles[9176:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSOrderedSetM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(0x3099ae83 0x3acf76c7 0x3092ed87 0xd17fb 0x33251315 0x331f96cd 0x331f8ef1 0x3311f353 0x32da5943 0x32da1167 0x32da0ff9 0x32da0a0d 0x32da081f 0x3311768b 0x30965f69 0x309638f7 0x30963c43 0x308ce471 0x308ce253 0x356082eb 0x33183845 0xbff3d 0x3b1f0ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

为什么objectAtSedex:3可以在numberOfSections方法的NSLog中重试,但不能在cellForRow方法中重试?

修改

我不知道这是否相关,但是几天前(当我的日历仍然有点工作时)我发布了一个关于奇怪事情的问题:UITableView Search Causes Strange Scrolling

0 个答案:

没有答案