0

我从互联网上获取了一个类似于脉冲的应用程序示例脚本,该脚本由 xib 文件组成,我将其构建为进入情节提要以利用水平表格滚动。

出于某种原因,tableView.m 中的“cell = tableViewCell”一直因断言失败而对我失败 UITableView dataSource 必须从 tableView 返回一个单元格:cellForRowAtIndexPath

如果我注释掉“cell = tableViewCell”,程序运行不会失败,但我没有将信息传递给 tableViewCell。

有没有我看不到的简单解决方案?

表视图.m

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


       CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
       tableViewCell.horizontalTableView.transform = rotateTable;
       tableViewCell.horizontalTableView.frame = CGRectMake(0, 0, tableViewCell.horizontalTableView.frame.size.width, tableViewCell.horizontalTableView.frame.size.height);

       tableViewCell.contentArray = [arrays objectAtIndex:indexPath.section];

       tableViewCell.horizontalTableView.allowsSelection = YES;
       cell = tableViewCell;

     return cell;
 } 

tableViewCell.m

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

   for (UIImageView *view in cell.subviews) {
       [view removeFromSuperview];
   }

   UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
   imageView.image = [contentArray objectAtIndex:indexPath.row]];
   imageView.contentMode = UIViewContentModeCenter;

   CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2);
   imageView.transform = rotateImage;

   [cell addSubview:imageView];

   return cell;
}
4

1 回答 1

0

如果 dequeue 返回 nil,您应该只分配和初始化一个新的表格单元格。

if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}

您使用的示例http://iosstuff.wordpress.com/2011/06/29/creating-pulse-style-scrolling-horizo​​ntally-scrolling-uitableview-as-a-subview-of-uitableviewcell / 真的很旧iOS 4。去年在 iOS 6 中,Apple 添加了 Collection Views 来完成这些类型的事情。

你应该检查一下:

WWW2012 会议 205:介绍集合视图 https://developer.apple.com/videos/wwdc/2012/?id=205

第 7 讲集合视图 https://itunes.apple.com/us/course/coding-together-developing/id593208016

于 2013-05-16T06:18:29.993 回答