繁体   English   中英

无法在iOS App中重新加载TableView数据

[英]Unable to reload TableView Data in iOS App

我发现自己的想法使该应用程序无法正常工作。 我的应用程序使用拆分视图显示到列表。 “主”列表应包含用户的Facebook朋友列表。 由于该应用程序不会强制您登录,因此,如果您尚未登录,但在登录之前,列表中会显示“您没有朋友”。我的问题是,一旦我加载了所有朋友并致电[self.tableView reloadData]我的程序在那里崩溃了,尽管我尽最大努力调试它,但我找不到它。 方法是

    - (void)request:(FBRequest *)request didLoad:(id)result
    {
        if ([result isKindOfClass:[NSArray class]] && ([result count] > 0)) {
            result = [result objectAtIndex:0];
        }
        switch (((Facebook *)[Facebook shared]).currentCall) {
            case graphUserFriends:
            {
                _friends = [NSMutableArray array];
                NSArray *resultData = [result objectForKey:@"data"];
                if ([resultData count] > 0) 
                {
                    for (NSUInteger i=0; i<[resultData count] && i < 25; i++) 
                    {
                        NSDictionary *friendDictionary = [resultData objectAtIndex:i];
                        FbFriend * f = [[[FbFriend alloc] initWithName:[friendDictionary objectForKey:@"name"] Id:[friendDictionary objectForKey:@"id"]] autorelease];
                        [_friends addObject:f];
                    }
                }
                [self.tableView reloadData];
                break;
            }
            default:
                break;
        }
    }

整个源代码(和Xcode 4项目)可以从https://skydrive.live.com/redir.aspx?cid=04b38cdd7b38bb7f&resid=4B38CDD7B38BB7F!798&parid=4B38CDD7B38BB7F!470&authkey=!API4iVva95nZFL8下载

控制台(崩溃时):

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 48870.
Catchpoint 3 (throw)Pending breakpoint 1 - "objc_exception_throw" resolved
Current language:  auto; currently objective-c
(gdb) bt
#0  0x0156ecf0 in objc_exception_throw ()
#1  0x013c9674 in -[__NSArrayI objectAtIndex:] ()
#2  0x00454805 in -[UITableViewDataSource tableView:heightForRowAtIndexPath:] ()
#3  0x0026427a in -[UITableViewController tableView:heightForRowAtIndexPath:] ()
#4  0x0020f548 in -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] ()
#5  0x00211722 in -[UITableViewRowData numberOfRows] ()
#6  0x000c17c7 in -[UITableView noteNumberOfRowsChanged] ()
#7  0x000c12c1 in -[UITableView reloadData] ()
#8  0x0000247e in -[MasterViewController request:didLoad:] (self=0x6a491e0, _cmd=0x12e65, request=0x681e930, result=0x6824250) at /Users/CheckM8/Documents/Xcode 4/Projects/iPeople4/iPeople4/MasterViewController.m:46
#9  0x00009d36 in -[FBRequest handleResponseData:] (self=0x681e930, _cmd=0x1397a, data=0x6a76c60) at /Users/CheckM8/Documents/Xcode 4/facebook-facebook-ios-sdk-74358cd/src/FBRequest.m:261
#10 0x0000a357 in -[FBRequest connectionDidFinishLoading:] (self=0x681e930, _cmd=0xade62e, connection=0x681ec40) at /Users/CheckM8/Documents/Xcode 4/facebook-facebook-ios-sdk-74358cd/src/FBRequest.m:346
#11 0x00a29a59 in ___NSURLConnectionDidFinishLoading_block_invoke_0 ()
#12 0x00a27e94 in __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 ()
#13 0x00a28eb7 in -[NSURLConnectionInternalConnection invokeForDelegate:] ()
#14 0x00a27e4f in -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] ()
#15 0x00a27fd5 in -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] ()
#16 0x0096cf6a in _NSURLConnectionDidFinishLoading ()
#17 0x0398fbbd in URLConnectionClient::_clientDidFinishLoading ()
#18 0x03a5c5ea in URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload ()
#19 0x03986298 in URLConnectionClient::processEvents ()
#20 0x03a5c16b in non-virtual thunk to URLConnectionInstanceData::multiplexerClientPerform() ()
#21 0x03986137 in MultiplexerSource::perform ()
#22 0x013b197f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#23 0x01314b73 in __CFRunLoopDoSources0 ()
#24 0x01314454 in __CFRunLoopRun ()
#25 0x01313db4 in CFRunLoopRunSpecific ()
#26 0x01313ccb in CFRunLoopRunInMode ()
#27 0x012c6879 in GSEventRunModal ()
#28 0x012c693e in GSEventRun ()
#29 0x00034a9b in UIApplicationMain ()
#30 0x00001d82 in main (argc=1, argv=0xbfffed64) at /Users/CheckM8/Documents/Xcode 4/Projects/iPeople4/iPeople4/main.m:16
#31 0x00001cf5 in start ()

您犯了经典的内存管理错误:您直接访问ivars,这烧死了您。

_friends = [NSMutableArray array];

这是一个保留不足(稍后会崩溃),并且如果_friends具有先前值,则可能会泄漏。 除dealloc和init外,您应始终对ivars使用访问器:

self.friends = [NSMutableArray array];
...
[self.friends addObject:f];

编辑:从您的stacktrace,您的错误是在您的表视图数据源的tableView:heightForRowAtIndexPath: 好像您正在读取数组的末尾。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM