我已創建了一個選項卡表視圖,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條記錄。
請幫幫我!!!
感謝
堆棧跟蹤以及相關的源文件,請。 – trojanfoe 2014-09-02 13:41:48
對不起,我發佈了代碼。我無法提供u文件和其他東西 – svrushal 2014-09-02 13:43:56
好吧,我懷疑任何人都可以幫助。 – trojanfoe 2014-09-02 13:44:23