0

I can't see to work out whats the problem, Ive traced the origin of the code but Dont know what to do. Here is the log

2015-03-09 12:12:35.093 My Movies[1785:10474] Application windows are expected to have a root view controller at the end of application launch
2015-03-09 12:12:35.109 My Movies[1785:10474] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFConstantString 0x106c39148> valueForUndefinedKey:]: this class is not key value coding-compliant for the key title.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001074cdf35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000107166bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001074cdb79 -[NSException raise] + 9
    3   Foundation                          0x0000000106d9430a -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
    4   Foundation                          0x0000000106cec823 -[NSObject(NSKeyValueCoding) valueForKey:] + 251
    5   My Movies                           0x0000000106c34a1e -[FilmTableTableViewController tableView:cellForRowAtIndexPath:] + 526
    6   UIKit                               0x00000001079b14b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
    7   UIKit                               0x0000000107990fb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
    8   UIKit                               0x00000001079a6e3c -[UITableView layoutSubviews] + 213
    9   UIKit                               0x0000000107933973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
    10  QuartzCore                          0x000000010b1a8de8 -[CALayer layoutSublayers] + 150
    11  QuartzCore                          0x000000010b19da0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    12  QuartzCore                          0x000000010b19d87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    13  QuartzCore                          0x000000010b10b63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    14  QuartzCore                          0x000000010b10c74a _ZN2CA11Transaction6commitEv + 390
    15  UIKit                               0x00000001078b854d -[UIApplication _reportMainSceneUpdateFinished:] + 44
    16  UIKit                               0x00000001078b9238 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2642
    17  UIKit                               0x00000001078b7bf2 -[UIApplication workspaceDidEndTransaction:] + 179
    18  FrontBoardServices                  0x000000010a0762a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    19  CoreFoundation                      0x000000010740353c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    20  CoreFoundation                      0x00000001073f9285 __CFRunLoopDoBlocks + 341
    21  CoreFoundation                      0x00000001073f9045 __CFRunLoopRun + 2389
    22  CoreFoundation                      0x00000001073f8486 CFRunLoopRunSpecific + 470
    23  UIKit                               0x00000001078b7669 -[UIApplication _run] + 413
    24  UIKit                               0x00000001078ba420 UIApplicationMain + 1282
    25  My Movies                           0x0000000106c36dc3 main + 115
    26  libdyld.dylib                       0x0000000109a5d145 start + 1
    27  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

My code

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

    // Configure Cell
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSDictionary *movie = searching ? [searchResults objectAtIndex:[indexPath row]] :
                                    [films objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[movie valueForKey:@"title"]];
    [[cell detailTextLabel] setText:[[movie valueForKey:@"year"] description]];
    return cell;

it leads to the line.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

Ive been following a tutorial on objective all this time and just bee following its steps, so I don't know where ive gone wrong.

  • Why do you say that the problematic line is the `dequeue` ? Are you sure the `movie` object is a `NSDictionary` ? – Francesco Mar 09 '15 at 12:24
  • @Francesco is right. In some cases the movie isn´t a dictionary or at least does´t implement "title" or "year" as a key. – Onik IV Mar 09 '15 at 12:26
  • 1
    @OnikIV I should say in some cases it is a `NSString`, reading the exception trace. – Francesco Mar 09 '15 at 12:30
  • take a look at this http://stackoverflow.com/questions/7520971/applications-are-expected-to-have-a-root-view-controller-at-the-end-of-applicati. You have problems even before you UITableView. So I do think that you should adjust that one first and see what you get. The code you post looks fine to me. – Yuchen Mar 09 '15 at 14:06

0 Answers0