UITableView适用于iOS 7,但在iOS 8中出现粉碎

问题描述:

这里还是iOS编程的新手。有一个UITableView在iOS 7上完美工作,但在iOS 8中显示为崩溃。多个设备。当使用模拟器(iOS 7与iOS 8模拟器)时也会出现相同的问题/差异。UITableView适用于iOS 7,但在iOS 8中出现粉碎

我在Xcode的6公测6,优山美地测试6,iOS的7.12和iOS 8的测试版5.

我所做的这些简单的代码,完整地展现了问题:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
     // Return the number of sections. 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     // Return the number of rows in the section. 
     return [self.numberOfDays count]; 
    } 

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

     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ]; 

     NSLog (@"%li", (long)indexPath.row); 

     UILabel *label; 
     label = (UILabel *)[cell viewWithTag:1]; 
     label.text = @"Monday"; 

     return cell; 
    } 

注意我的NSLog语句。我的UIViewTable(0-87)有88行。

  • 当iOS的7本表负荷......

    • 我得到了我的控制台12线
    • 因为因为这是可见的行的初始数量这使得
    • 表滚动得很好,顺畅......一切都与世界的好。
  • 当iOS 8的这台负载...

    • 我得到88线在我的控制台
    • 这没有任何意义,我反正
    • 的初始外观表看起来不错
    • eg前12行显示正确
    • 表格不能正确滚动。
    • 第12-87行出现约1个像素高。

表中的初始外观看起来行(例如,第一行12中正确显示),直到我尝试滚动经过它。然后12-87行出现约1个像素高。

请帮助!

好吧 - 这很简单,只需添加: tableView.rowHeight = 44;我的静态NSString * CellIdentifier = @“Cell”后的 ;线。 我也没必要,这是iOS的7,不知道为什么我需要它的iOS 8

确定 - 它是那样简单添加:

tableView.rowHeight = 44; 

后我

static NSString *CellIdentifier = @"Cell"; 

一行。我不需要这是iOS 7,不知道为什么我需要它在iOS 8。

您的解决方案可能会奏效,但它会更好地执行heightForRowAtIndexPath方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
     return 44; 
} 

我不知道为什么有iOS的7和8之间的差异,也许别人可以阐明一些轻?