0

KGModal ビュー ( https://github.com/kgn/KGModal ) に動作する TableView を設定しようとしていますが、JSON を介してデータを取得した後、アプリがクラッシュすることなく reloadData を実行できません。

このcellForRowAtIndexPathメソッドは JSON の結果を適切に返しています。_tv は KGModal で既に使用されているため、reloadData メソッドに問題があると思いますか? itemNutriFeed.*単なる JSON モデルです。

//itemNutriModal.h

#import <UIKit/UIKit.h>

@interface itemNutriModal : UIViewController <UITableViewDataSource, UITableViewDelegate>
- (void)showNutri; //:(NSArray*)nutri;
@end

//itemNutriModal.m

#import "itemNutriModal.h"
#import "JSONModelLib.h"
#import "itemNutriFeed.h"
#import "KGModal.h"

@interface itemNutriModal () {
    itemNutriFeed* _feed;
    UITableView* _tv;
}

@end

@implementation itemNutriModal
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)showNutri //:(NSArray*)nutri
{
  _tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 400)];
  _tv.backgroundColor = [UIColor clearColor];
  _tv.scrollEnabled = FALSE;
 [_tv setDataSource:self];
 [_tv setDelegate:self];


[[KGModal sharedInstance] showWithContentView:_tv andAnimated:YES];

_feed = [[itemNutriFeed alloc] initFromURLWithString:@"http://c..../.../nutri.php?inid=1000"
                                          completion:^(JSONModel *model, JSONModelError *err) {

                                              //hide the loader view
                                              //[HUD hideUIBlockingIndicator];

                                              //json fetched
                                              NSLog(@"Results: %@", _feed.results);

                                              [_tv reloadData];


                                          }];

//;



//NSLog(@"SHOW NUTRIS!");
}

#pragma mark - TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"nutriTableCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleValue1
            reuseIdentifier:CellIdentifier];
}

itemNutriModel* nutrivals = _feed.results[indexPath.row];

NSLog(@"nutrivals: %@", _feed.results);

cell.backgroundColor = [UIColor clearColor];
[cell.textLabel setTextColor:[UIColor whiteColor]];
[cell.textLabel setText:[NSString stringWithFormat:@"%@", nutrivals.type]];
[cell.detailTextLabel setText:[NSString stringWithFormat:@"%@", nutrivals.value]];

return cell;
}
@end

[[KGModal sharedInstance] showWithContentView:_tv andAnimated:YES];JSON 補完メソッドに配置することもクラッシュします。

クラッシュは EXC_BAD_ACCESS を示します。

2013-08-30 19:13:56.634 xapp[91159:a0b] *** -[itemNutriModal tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0xd8add90

---- 最初の cellForRowAtIndexPath 呼び出しでのスタック トレース (動作) ----

2013-08-30 19:34:00.229 xapp[91619:a0b] Stack trace : (
    0   xapp                                0x0002dec3 -[itemNutriModal showNutri] + 483
    1   xapp                                0x0001a60f -[favouritesTableViewController tableView:accessoryButtonTappedForRowWithIndexPath:] + 175
    2   UIKit                               0x009baa25 -[UITableView _accessoryButtonAction:] + 310
    3   libobjc.A.dylib                     0x01b7c874 -[NSObject performSelector:withObject:withObject:] + 77
    4   UIKit                               0x008e424c -[UIApplication sendAction:to:from:forEvent:] + 108
    5   UIKit                               0x008e41d8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    6   UIKit                               0x009daa5d -[UIControl sendAction:to:forEvent:] + 66
    7   UIKit                               0x009dae20 -[UIControl _sendActionsForEvents:withEvent:] + 577
    8   UIKit                               0x009da0cf -[UIControl touchesEnded:withEvent:] + 641
    9   UIKit                               0x00c5440f _UIGestureRecognizerUpdate + 7166
    10  UIKit                               0x00920e9a -[UIWindow _sendGesturesForEvent:] + 1291
    11  UIKit                               0x00921dba -[UIWindow sendEvent:] + 1030
    12  UIKit                               0x008f5b86 -[UIApplication sendEvent:] + 242
    13  UIKit                               0x008e035f _UIApplicationHandleEventQueue + 11421
    14  CoreFoundation                      0x01d7396f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    15  CoreFoundation                      0x01d732fb __CFRunLoopDoSources0 + 235
    16  CoreFoundation                      0x01d903ce __CFRunLoopRun + 910
    17  CoreFoundation                      0x01d8fbf3 CFRunLoopRunSpecific + 467
    18  CoreFoundation                      0x01d8fa0b CFRunLoopRunInMode + 123
    19  GraphicsServices                    0x03125a27 GSEventRunModal + 192
    20  GraphicsServices                    0x0312584e GSEventRun + 104
    21  UIKit                               0x008e2f0b UIApplicationMain + 1225
    22  xapp                                0x0001313d main + 141
    23  libdyld.dylib                       0x03d05725 start + 0
)

---- JSON 完了からの 2 回目の cellForRowAtIndexPath 呼び出しのスタック トレース (例外) ----

2013-08-30 19:34:00.332 xapp[91619:a0b] Stack trace : (
    0   xapp                                0x0002e1a6 __27-[itemNutriModal showNutri]_block_invoke + 230
    1   xapp                                0x0000b3d0 __58-[JSONModel(Networking) initFromURLWithString:completion:]_block_invoke_2 + 112
    2   libdispatch.dylib                   0x03a60818 _dispatch_call_block_and_release + 15
    3   libdispatch.dylib                   0x03a754b0 _dispatch_client_callout + 14
    4   libdispatch.dylib                   0x03a62a0e _dispatch_after_timer_callback + 98
    5   libdispatch.dylib                   0x03a754b0 _dispatch_client_callout + 14
    6   libdispatch.dylib                   0x03a6be6b _dispatch_source_latch_and_call + 150
    7   libdispatch.dylib                   0x03a66443 _dispatch_source_invoke + 411
    8   libdispatch.dylib                   0x03a636f6 _dispatch_main_queue_callback_4CF + 228
    9   CoreFoundation                      0x01e4fb6e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
    10  CoreFoundation                      0x01d907eb __CFRunLoopRun + 1963
    11  CoreFoundation                      0x01d8fbf3 CFRunLoopRunSpecific + 467
    12  CoreFoundation                      0x01d8fa0b CFRunLoopRunInMode + 123
    13  GraphicsServices                    0x03125a27 GSEventRunModal + 192
    14  GraphicsServices                    0x0312584e GSEventRun + 104
    15  UIKit                               0x008e2f0b UIApplicationMain + 1225
    16  xapp                                0x0001313d main + 141
    17  libdyld.dylib                       0x03d05725 start + 0
)
4

2 に答える 2

0

これは KGModal に問題があるようです。KGModal オブジェクトに割り当てるときにビュー/コントローラーの割り当てを解除すると、reloadData コマンドで操作できなくなります。

これを回避する方法は、独自のカスタム UIScrollView を作成し、モーダル ウィンドウに割り当てる前にデータを入力することでした。

于 2013-09-01T23:36:06.413 に答える