2016-10-10 77 views
0

我是新來的iOS開發人員。我正在製作一個應用程序,我從JSON獲取響應。但是當我點擊按鈕顯示下一個UITableView。 我有兩個問題給大家。因未捕獲異常'NSRangeException'而終止應用程序,原因:' - [__ NSCFArray objectAtIndex:]:index(14)beyond bounds(14)'

1)之前會顯示空值。我必須向下滾動顯示值。

2.)向下滾動調試錯誤後是節目 「終止應用程序由於未捕獲的異常 'NSRangeException',原因:「 - [__ NSCFArray objectAtIndex:]:索引(14)超出界限(14)」

Picture for shown scroll down to show datas

對不起,我的英語不好。我可以說一點英語。

我們必須點擊按鈕才能進入下一個UITableView。

- (IBAction)btnf10 
{ 
    NSMutableDictionary *content = [NSMutableDictionary dictionary]; 
    [content setValue:[[AppSetting sharedInstance] token] forKey:@"ewitoken"]; 
    //[content setValue:gloablOnWherehouse.selectedWhereHouse forKey:@"model_Name"]; 
    [[EWIConnector connector] requestEWIService:@"special_selected_f10" requestData:content delegate:self]; 
} 

而requestEWIServiceStart將檢查字符串。

- (void) requestEWIServiceStart:(EWIConnector *)connector{ 

     NSLog(@"start %@",connector.endpoint); 
    } 

    - (void) requestEWIServiceFinish:(EWIConnector *)connector responseData:(NSDictionary *)responseData{ 

     NSLog(@"finish %@",connector.serviceName); 
     NSLog(@"response %@",responseData); 

     if ([connector.serviceName isEqualToString:@"special_selected_f10"]) 
     { 
      NSLog(@"finish %@",connector.serviceName); 
      NSDictionary *content = responseData[@"content"]; 
      NSString *stAlertMes = [content objectForKey:@"alertMessage"]; 
      stAlertMes = [self getString:stAlertMes]; 
      NSLog(@"AlertMSG : %@", stAlertMes); 
      if (![stAlertMes isEqualToString:@""]) { 
       NSLog(@"ALERT MESSAGE : %@", stAlertMes); 
       gloablOnWherehouse.arTableDataSelected = [[NSArray alloc] init]; 
      } 
      else 
      { 
       NSLog(@"HAS DATA"); 
       gloablOnWherehouse.arTableDataSelected = [content objectForKey:@"DataList_SPI_DetailCollection"]; 
       [self.tableViewWhereHoseList reloadData]; 

       labelStatus.text = @"F11"; 

      } 
     } 
     else 
    { 
     NSLog(@"response %@",responseData); 
    } 
} 

UITableView 2用於響應數據。

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    globlOnDisplayEffect = [GlobalVariable sharedInstance]; 
    globlOnDisplayEffect.arTableDataSelectedWhereHouse = [[NSArray alloc] init]; 
    [self.tableViewDetailList reloadData]; 

} 

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

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return (globlOnDisplayEffect.arTableDataSelected)?[globlOnDisplayEffect.arTableDataSelected count]: 100; 
} 



- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *simpleTableIdentifier = @"DisplayEffectQtyViewCell"; 
    DisplayEffectQtyViewCell *cell = [self.tableViewDetailList dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath]; 
    if(cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DisplayEffectQtyViewCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 

    } else { 
     if (globlOnDisplayEffect.arTableDataSelected) { 
      NSMutableArray *myMutbleArray = [[NSMutableArray alloc] init]; 
      [myMutbleArray addObject:globlOnDisplayEffect.arTableDataSelected]; 

      if (myMutbleArray) { 
       NSDictionary *myDic = [globlOnDisplayEffect.arTableDataSelected objectAtIndex:indexPath.row]; 
       NSDictionary *cont = [myDic objectForKey:@"DataList_SPI_DetailF10"]; 
       NSString *f10_cmpt = [self getString:[cont objectForKey:@"f10_cmpt"]]; 
       NSString *f10_dt = [self getString:[cont objectForKey:@"f10_dt"]]; 
       NSString *f10_item = [self getString:[cont objectForKey:@"f10_item"]]; 
       NSString *f10_lot = [self getString:[cont objectForKey:@"f10_lot"]]; 
       NSString *f10_model = [self getString:[cont objectForKey:@"f10_model"]]; 
       NSString *f10_of = [self getString:[cont objectForKey:@"f10_of"]]; 
       NSString *f10_semi = [self getString:[cont objectForKey:@"f10_semi"]]; 
       NSString *f10_tm = [self getString:[cont objectForKey:@"f10_tm"]]; 
       NSString *f10_uncmp = [self getString:[cont objectForKey:@"f10_uncmp"]]; 

       [cell setf10_cmpt:f10_cmpt setf10_dt:f10_dt setf10_item:f10_item setf10_lot:f10_lot setf10_model:f10_model setf10_of:f10_of setf10_semi:f10_semi setf10_tm:f10_tm setf10_uncmp:f10_uncmp]; 


      } 
     } 
    } 
    return cell; 

} 
+0

添加異常斷點以查看發生錯誤的位置。 – RomOne

+0

當我是異常斷點。它在 「DisplayEffectQtyViewCell * cell = [self.tableViewDetailList dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];」我從空白單元格向下滾動到單元格上的顯示值。 –

回答

0

索引數組綁定,這是一個常見的問題。陣列中沒有第14個位置的對象。

在加載tableview之前,使用循環在控制檯中顯示所有數據,您必須在Cell中顯示所有數據。

else 
     { 
      NSLog(@"HAS DATA"); 
      gloablOnWherehouse.arTableDataSelected = [content objectForKey:@"DataList_SPI_DetailCollection"]; 

      // [self.tableViewWhereHoseList reloadData]; 

      labelStatus.text = @"F11"; 

     } 

並且還檢查您正在加載哪個表視圖並將其計數。我想,這應該是

[globlOnDisplayEffect.arTableDataSelected count]>0 ?[globlOnDisplayEffect.arTableDataSelected count]:100. 

解釋一下,爲什麼你會顯示100細胞時[globlOnDisplayEffect.arTableDataSelected計數] == 0。其他的數據源是什麼?

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

// NSLog what you return.... 
return (globlOnDisplayEffect.arTableDataSelected)?[globlOnDisplayEffect.arTableDataSelected count]: 100; 
} 

檢查你的表單元格條件也。 **

+0

哦,抱歉錯誤的返回值(100)。我會寫回報的價值是1. 現在你的代碼可以解決我的問題。但我有一個問題。 如何解決第一個問題。因爲我只能向下滾動顯示數據。 –

+0

請先修復它。希望第二個問題會自動解決。您的表格單元格沒有獲取單元格的數據,因此導致崩潰。如果您得到解決方案,請立即投票並接受我的回答。 @รัฐพงศ์ตุรงค์เรือง –

+0

我解決了你的評論。這是工作(這不是數組中的錯誤)。但UITable在向下滾動之前無法響應數據。請幫幫我。 –

相關問題