簡體   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