0

オブジェクトの配列をループしてから、キー「リゾート」の値を取得し、それがまだ存在しない場合は別の配列に格納しています。

私の NSLog の結果は、文字列がそこにあることを示しています。ただし、この質問のタイトルに記載されているエラーが発生します。文字列「resortName」を「location」に置き換えてオブジェクト全体を保存すると、エラーはなくなります。

問題は、文字列を確認する必要があることです。これが、この機会に重複したオブジェクトが保存されるのを防ぐ唯一の方法だからです。

objects はパース PFObjects の NSArray です

これが私のコードです:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    for location in objects {

        var resortName = location.valueForKey("resort") as NSString
        NSLog("resortname: \(resortName)")

        if !_sections.containsObject(resortName) {
            _sections.addObject(resortName)
        }
    }

    NSLog("sections: \(_sections.count)")
    return _sections.count
}

私が間違っていることは何ですか?

御時間ありがとうございます。

完全なスタック:

2014-09-11 16:42:08.635 CharityApp[33639:380242] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x7fa325842340> valueForUndefinedKey:]: this class is not key value coding-compliant for the key resort.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f8293f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001113febb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010f829039 -[NSException raise] + 9
    3   Foundation                          0x000000010fcd0fba -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
    4   Foundation                          0x000000010fc29543 -[NSObject(NSKeyValueCoding) valueForKey:] + 251
    5   CharityApp                          0x000000010df14ed0 _TFC8CharityApp31ActivityListTableViewController9tableViewfS0_FTCSo11UITableView23titleForHeaderInSectionSi_GSqSS_ + 976
    6   CharityApp                          0x000000010df150ac _TToFC8CharityApp31ActivityListTableViewController9tableViewfS0_FTCSo11UITableView23titleForHeaderInSectionSi_GSqSS_ + 92
    7   UIKit                               0x000000011024c8e1 -[UITableView _delegateWantsHeaderTitleForSection:] + 56
    8   UIKit                               0x000000011024c8a5 -[UITableView _delegateWantsHeaderForSection:] + 572
    9   UIKit                               0x00000001103cf81e -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 162
    10  UIKit                               0x00000001103d55ec -[UITableViewRowData rectForSection:] + 302
    11  UIKit                               0x00000001103d6583 -[UITableViewRowData indexPathsForRowsInRect:] + 90
    12  UIKit                               0x000000011023f0ed -[UITableView indexPathsForVisibleRows] + 269
    13  CharityApp                          0x000000010df5f39a -[PFQueryTableViewController loadImagesForOnscreenRows] + 137
    14  UIKit                               0x00000001101efb4f -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 277
    15  UIKit                               0x00000001101efd69 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 479
    16  UIKit                               0x00000001101ea53a -[UIScrollView _smoothScrollWithUpdateTime:] + 2896
    17  QuartzCore                          0x000000010e54a8f7 _ZN2CA7Display15DisplayLinkItem8dispatchEv + 37
    18  QuartzCore                          0x000000010e54a7bf _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 315
    19  CoreFoundation                      0x000000010f7914e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    20  CoreFoundation                      0x000000010f7910a5 __CFRunLoopDoTimer + 1045
    21  CoreFoundation                      0x000000010f7543dd __CFRunLoopRun + 1901
    22  CoreFoundation                      0x000000010f753a06 CFRunLoopRunSpecific + 470
    23  GraphicsServices                    0x0000000111bc19f0 GSEventRunModal + 161
    24  UIKit                               0x000000011015a550 UIApplicationMain + 1282
    25  CharityApp                          0x000000010dedd7ae top_level_code + 78
    26  CharityApp                          0x000000010dedd8ca main + 42
    27  libdyld.dylib                       0x00000001122ca145 start + 1
    28  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
4

1 に答える 1