2014-09-02 94 views
-1

我已創建了一個選項卡表視圖,E編程代碼如下:索引0超出界限爲空數組對於iOS 8

我添加上
 tblWebserviceList=[[UITableView alloc] initWithFrame:CGRectMake(345, 304, 430, 180)]; 
     tblWebserviceList.delegate=self; 
     tblWebserviceList.dataSource=self; 
     tblWebserviceList.rowHeight=30; 
     [WebServiceView addSubview:tblWebserviceList]; 

現在這個表視圖名爲WebServiceView一個視圖中添加一個按鈕點擊

爲表視圖委託方法是如下

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 
//------------------------------------------------------------------------ 
// Method : numberOfRowsInSection 
// method to set the number of row in the tableview 
//------------------------------------------------------------------------ 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
      if(arrWebServiceList==nil) 
       return 0; 

      return [arrWebServiceList count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if(cell==nil) 
      { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
       cell.selectionStyle=UITableViewCellSelectionStyleNone; 
      } 
      cell.textLabel.font=[UIFont fontWithName:@"Helvetica" size:15]; 
      cell.textLabel.text=[arrWebServiceList objectAtIndex:indexPath.row]; 
      return cell; 
} 

在一個按鈕點擊我有如下添加WebServiceView的代碼:

tblWebserviceList.hidden=YES; 
    [self.view addSubview:WebServiceView]; 

這裏補充說,父視圖之前我爲隱藏tblWebserviceList並顯示在需要時,

這是所有的代碼。

現在我的問題是這個代碼運行良好的ios 7.0和7.1。

但是應用程序在ios 8.0上崩潰。要使用的Xcode公測6調試代碼IM 6.

崩潰日誌是

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' 
*** First throw call stack: 
(0x22c6bf77 0x30134c77 0x22b803d7 0x40b94f 0x26315501 0x263192db 0x2624434f 0x25c724c5 0x25c6dec1 0x25c6dd49 0x25c6d737 0x25c6d541 0x25c6744d 0x22c32835 0x22c2ff19 0x22c3031b 0x22b7dda1 0x22b7dbb3 0x2a063051 0x262a5c41 0x53aed 0x53438) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

我認爲當表中的第一次數據源數組包含0只記錄來因爲最初我這個問題顯示空表,然後在插入Web服務URL後添加記錄。

如果記錄大於0,那麼它會正常工作。只發出0條記錄。

請幫幫我!!!

感謝

+0

堆棧跟蹤以及相關的源文件,請。 – trojanfoe 2014-09-02 13:41:48

+0

對不起,我發佈了代碼。我無法提供u文件和其他東西 – svrushal 2014-09-02 13:43:56

+0

好吧,我懷疑任何人都可以幫助。 – trojanfoe 2014-09-02 13:44:23

回答

0

改變這一行

cell.textLabel.text=[arrWebServiceList objectAtIndex:indexPath.row]; 

cell.textLabel.text = [arrWebServiceList count] > 0 ? [arrWebServiceList objectAtIndex:indexPath.row] : @"DummyText"; 
+0

對於空數組,控制不進入cellForRowAtIndePath函數。我已經調試過了。對於空陣列我返回行數= 0 – svrushal 2014-09-02 14:00:26

+0

@svrushal,它不應該,但誰知道什麼是ios 8 beta – 2014-09-02 14:02:03

+0

@ Cy-4AH,但我希望我的應用程序應該運行在ios 8上。這就是爲什麼即時檢查它。 – svrushal 2014-09-02 14:07:19

相關問題