【问题标题】:Crash due to CALayer bounds contains NaN: [0 0; nan 20]由于 CALayer 边界导致的崩溃包含 NaN:[0 0;南20]
【发布时间】:2011-09-12 17:52:18
【问题描述】:

我正在开发一个 iOS 应用程序,该应用程序在选项卡栏中包含表格视图,但是当用户按下选项卡栏时,应用程序崩溃,我不确定为什么 - 崩溃是由于 CALayer 边界包含 NaN:[0 0; nan 20] 虽然我不知道该怎么做...下面是代码:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
#if USE_CUSTOM_DRAWING  const NSInteger TOP_LABEL_TAG = 1001;   const NSInteger BOTTOM_LABEL_TAG = 1002;    UILabel *topLabel;  UILabel
*bottomLabel;
#endif      static NSString *CellIdentifier = @"Cell";  UITableViewCell
*cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];  if (cell == nil)    {           //          // Create the cell.             //      cell =      [[[UITableViewCell alloc]
          initWithFrame:CGRectZero
          reuseIdentifier:CellIdentifier]        autorelease];      
#if USE_CUSTOM_DRAWING      UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];        cell.accessoryView =        [[[UIImageView alloc]
          initWithImage:indicatorImage]          autorelease];
                const CGFloat LABEL_HEIGHT = 20;        UIImage *image = [UIImage imageNamed:@"imageA.png"];
                    //          // Create the label for the top row of text             //      topLabel =      [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     image.size.width + 2.0 * cell.indentationWidth,
                     0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT),
                     aTableView.bounds.size.width -
                     image.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width,
                     LABEL_HEIGHT)]          autorelease];      [cell.contentView addSubview:topLabel];
                    //          // Configure the properties for the text that are the same on every row             //      topLabel.tag = TOP_LABEL_TAG;       topLabel.backgroundColor = [UIColor clearColor];        topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];      topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];        topLabel.font = [UIFont fontWithName:@"Baskerville" size:25];
                    //          // Create the label for the top row of text             //      bottomLabel =       [[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     image.size.width + 2.0 * cell.indentationWidth,
                     0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT) + LABEL_HEIGHT,
                     aTableView.bounds.size.width -
                     image.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width,
                     LABEL_HEIGHT)];        [cell.contentView addSubview:bottomLabel];
                    //          // Configure the properties for the text that are the same on every row             //      bottomLabel.tag = BOTTOM_LABEL_TAG;         bottomLabel.backgroundColor = [UIColor clearColor];         bottomLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:0.5];       bottomLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];         bottomLabel.font = [UIFont fontWithName:@"Baskerville" size:15];
                    //          // Create a background image view.          //      cell.backgroundView =       [[[UIImageView alloc] init] autorelease];       cell.selectedBackgroundView =       [[[UIImageView alloc] init] autorelease];

#endif  }


#if USE_CUSTOM_DRAWING  else    {       topLabel = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG];         bottomLabel = (UILabel *)[cell viewWithTag:BOTTOM_LABEL_TAG];   }
            return cell; }

这里是实际文件的链接:http://cl.ly/A3Kt

【问题讨论】:

    标签: iphone crash ca


    【解决方案1】:

    问题是由使用initWithFrame:CGRectZero 引起的。将其替换为 CGRectMake(0,0,1,1)

    【讨论】:

      【解决方案2】:

      您可能混淆了UIImagesize 属性和CGRectsize 部分,即frameboundsbounds

      在构造UILabel 时,请尝试修改CGRectMake 中的第三个元素。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多