0

パルスに似たアプリのサンプル スクリプトをインターネットから取得しました。これは xib ファイルで構成されており、水平方向のテーブル スクロールを利用するためにストーリーボードに入るように構成しました。

何らかの理由で、tableView.m の "cell = tableViewCell" がアサーション エラーで失敗し続けます UITableView dataSource は tableView:cellForRowAtIndexPath からセルを返す必要があります

「cell = tableViewCell」をコメントアウトすると、プログラムは問題なく実行されますが、tableViewCell に情報が渡されません。

私が見ることができない簡単な解決策はありますか?

tableView.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

デキューが 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 に答える