2014-02-12 82 views
3

我使用下面的代碼 - UITableViewDataSource方法如下:爲什麼tableview中正常工作在iOS 6+模擬器,但在iOS 5的模擬器崩潰

numberOfRowsInSection

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

return [dataArray count]; 
} 

的cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

// Configure the cell... 
if (cell == nil) { 

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

cell.textLabel.text = dataArray[indexPath.row]; 

return cell; 
} 
+2

什麼是錯誤信息? –

回答

5
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

但在iOS 5中,創建的UITableViewCell的情況下,我們一般都採用這種方法: -

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

在iOS 5中,沒有必要額外的參數,你已經在iOS 6中使用過。只要放下它,它就會工作(forIndexPath :)。

2

沒有錯誤信息很難說。 但我認爲錯誤與dequeueReusableCellWithIdentifier:forIndexPath:有關,因爲此方法僅適用於iOS 6.0及更高版本。查看更多蘋果DOC https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier:forIndexPath:

+0

我無法找到 - 那麼最新的解決方案 –

+0

使用'dequeueReusableCellWithIdentifier:'代替(沒有索引路徑的版本) – sage444

相關問題