40

聞くのは、これを実装するために私が考えていることです。

本のようなページを実装したいのですが、このために UITableView と 90 度回転したセルとそのセルを 90 度取りたいのですが、UITableViewCell をサブクラス化したいのですが、このテーブルビュー セル内で UITableview を追加して、ユーザーができるようにします。垂直方向にスクロールしてコンテンツを表示し、水平方向にスクロールして回転したテーブルビューの次のセルに移動することもできます。これを実装するためのより良い方法はありますか?

4

5 に答える 5

73

はい、可能です。UITableViewセル内にUITableVIewを追加しました.. :)

xib ファイルに tableview セルを追加する必要はありません。UITableviewCell をサブクラス化し、以下のコードを使用するだけで、プログラムでセルが作成されます。

//in your main TableView 

#import "ViewController.h"
#import "CustomCell.h"
@interface ViewController ()<UITableViewDataSource , UITableViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad
 {
   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
 }

- (void)didReceiveMemoryWarning
  {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
  }

 - (void)dealloc 
{
 [_aTV release];
 [super dealloc];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
  return 1;
 }

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
  return 3;
 }

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   CustomCell *cell = [self.aTV dequeueReusableCellWithIdentifier:@"Cell"];
   if(cell == nil)
   {
     cell = [[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]autorelease];
   }

  cell.dataAraay = [NSMutableArray arrayWithObjects:@"subMenu->1",@"subMenu->2",@"subMenu->3",@"subMenu->4",@"subMenu->5", nil];
return  cell;
}

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


//in your custom tableview cell 
//  .m file
#import "CustomCell.h"

@implementation CustomCell 
@synthesize dataAraay; //array to hold submenu data

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
 {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    // Initialization code
   self.frame = CGRectMake(0, 0, 300, 50);
   UITableView *subMenuTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; //create tableview a

  subMenuTableView.tag = 100;
  subMenuTableView.delegate = self;
  subMenuTableView.dataSource = self;
  [self addSubview:subMenuTableView]; // add it cell
  [subMenuTableView release]; // for without ARC
  }
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
 {
     [super setSelected:selected animated:animated];

  // Configure the view for the selected state
 }

 -(void)layoutSubviews
 {
   [super layoutSubviews];
   UITableView *subMenuTableView =(UITableView *) [self viewWithTag:100];
   subMenuTableView.frame = CGRectMake(0.2, 0.3, self.bounds.size.width-5,    self.bounds.size.height-5);//set the frames for tableview

}

  //manage datasource and  delegate for submenu tableview
 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
     return 1;
  }

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
   return dataAraay.count;
 }

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if(cell == nil)
    {
       cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"]autorelease];
   }
  cell.textLabel.text = [self.dataAraay objectAtIndex:indexPath.row];

  return cell;

}

@end


Swiftバージョン内にsingle view projectアドを 作成し、そのおよびをセットアップしますtableviewstoryboarddatasourcedelegate

以下のコードを貼り付けてViewController.swift

  import UIKit

  class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
  }

  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }

  func numberOfSectionsInTableView(tableView: UITableView) -> Int {
      return 3;
  }

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      return 1;
  }

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
      var cell:CustomCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as?  CustomCell
      if cell == nil {
         cell = CustomCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
      }
      cell?.dataArr = ["subMenu->1","subMenu->2","subMenu->3","subMenu->4","subMenu->5"]
      return cell! 
   }

   func  tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
       return 150.0
   }
}

CustomCell.swiftのサブクラスであるUITableViewCell新しいファイルを作成します。このファイルdo not select with xibにはファイルがなく、のようにプログラムで作成されます。.xibtablecellobjective-c code

以下のコードを貼り付けてCustomCell.swift

  import UIKit

  class CustomCell: UITableViewCell,UITableViewDataSource,UITableViewDelegate {

  var dataArr:[String] = []
  var subMenuTable:UITableView?
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
      super.init(style: style , reuseIdentifier: reuseIdentifier)
      setUpTable()
  }

  required init(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
      setUpTable()
  }

  override func awakeFromNib() {
      super.awakeFromNib()
      // Initialization code
      setUpTable()
  }

  func setUpTable(){
      subMenuTable = UITableView(frame: CGRectZero, style:UITableViewStyle.Plain)
      subMenuTable?.delegate = self
      subMenuTable?.dataSource = self
      self.addSubview(subMenuTable!)
  }

  override func layoutSubviews() {
      super.layoutSubviews()
      subMenuTable?.frame = CGRectMake(0.2, 0.3, self.bounds.size.width-5, self.bounds.size.height-5)
  }

  override func setSelected(selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)
      // Configure the view for the selected state
  }

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      return dataArr.count
  }

  func numberOfSectionsInTableView(tableView: UITableView) -> Int {
      return 1
  }

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cellID")

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cellID")
    }

    cell?.textLabel?.text = dataArr[indexPath.row]

    return cell!
  }
}
于 2013-09-16T05:34:03.207 に答える
11

より良い方法:UIPageViewController左/右のページスクロールに a を使用します。各ページにはテーブル ビューを含めることができます。

于 2013-07-01T05:56:01.203 に答える
-1
#import "API.h"
#import "Parsing.pch"
#import "HomeViewController.h"
#import "ASIFormDataRequest.h"
#import "MBProgressHUD.h"
#import "UIImageView+WebCache.h"
#import "HomeCollectionViewCellForSubCat.h"
#import "CollectionViewTableViewCell.h"
#import "NewsTableViewCell.h"
#import "CategoryTableViewCell.h"
#import "HomeCollectionViewCellForSubCat.h"
#import "WebviewController.h"
#import "TopFreeAppsCollectionViewTableViewCell.h"
#import "TopSitesCollectionViewTableViewCell.h"
#import "TrandingVideoCollectionViewTableViewCell.h"
#import "SportsTableViewCell.h"
#import "JokesTableViewCell.h"
@interface HomeViewController ()
{
    MBProgressHUD *hud;
    NSMutableArray *Details;
    NSIndexPath *IndexPath;
    CollectionVIewTableViewCell *TrafficCell;
    NewsTableViewCell *NewsCell;
    CategoryTableViewCell *CategoryCell;
    TopFreeAppsCollectionViewTableViewCell *TopAppsCell;
    TopSitesCollectionViewTableViewCell *TopSitesCell;
    TrandingVideoCollectionViewTableViewCell *TrendingVideosCell;
    SportsTableViewCell *SportsCell;
    JokesTableViewCell *JokesCell;
}
@end
NSString *More;
NSMutableArray *news;

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.tableView.dataSource = self;
    self.tableView.delegate = self;

    self.automaticallyAdjustsScrollViewInsets = NO;
    //[self.navigationController setNavigationBarHidden:YES];


}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataArray.count;
}

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"Traffic" ])
    {
        if(!TrafficCell)
        {
            TrafficCell = [tableView dequeueReusableCellWithIdentifier:@"CollectionVIewTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            TrafficCell.Traffic = [dict valueForKey:@"detail"];
            [TrafficCell.collectionView reloadData];
            return TrafficCell;
        }
        return TrafficCell;
    }
    else if([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"News"])
    {
        if(!NewsCell)
        {
            NewsTableViewCell *cell = (NewsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NewsTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            cell.News = [dict valueForKey:@"detail"];
            [cell.NewsTableView reloadData];
            return cell;
        }
        return NewsCell;

    }
    else if ([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"TopApps"])
    {
        if(!TopAppsCell)
        {
            TopAppsCell = [tableView dequeueReusableCellWithIdentifier:@"TopFreeAppsCollectionViewTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            TopAppsCell.TopApps = [[dict valueForKey:@"detail"]valueForKey:@"small_banner"];
            [TopAppsCell.TopAppsCollectionView reloadData];
            return TopAppsCell;
        }
        return TopAppsCell;
    }

    else if ([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"TopSites"])
    {
        if(!TopSitesCell)
        {
            TopSitesCell = [tableView dequeueReusableCellWithIdentifier:@"TopSitesCollectionViewTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            TopSitesCell.TopSites = [dict valueForKey:@"detail"];
            [TopSitesCell.TopSitesCollectionView reloadData];
            return TopSitesCell;
        }
        return TopSitesCell;
    }

    else if ([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"Category"])
    {
        if(!CategoryCell)
        {
            CategoryCell= [tableView dequeueReusableCellWithIdentifier:@"CategoryTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            CategoryCell.Category = [dict valueForKey:@"detail"];
            [CategoryCell.CategorycollectionView reloadData];
            return CategoryCell;
        }
        return CategoryCell;
    }

    else if ([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"TrendingVideos"])
    {
        if(!TrendingVideosCell)
        {
            TrendingVideosCell= [tableView dequeueReusableCellWithIdentifier:@"TrandingVideoCollectionViewTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            TrendingVideosCell.TrendingVideos = [[dict valueForKey:@"detail"]valueForKey:@"small_banner"];
            [TrendingVideosCell.VideosCollectionView reloadData];
            return TrendingVideosCell;
        }
        return TrendingVideosCell;
    }

    else if ([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"Sports"])
    {
        if(!SportsCell)
        {
            SportsCell= [tableView dequeueReusableCellWithIdentifier:@"SportsTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            SportsCell.Sports = [dict valueForKey:@"detail"];
            [SportsCell.SportsTableView reloadData];
            return SportsCell;
        }
        return SportsCell;
    }

    else if ([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"Jokes"])
    {
        if(!JokesCell)
        {
            JokesCell= [tableView dequeueReusableCellWithIdentifier:@"JokesTableViewCell" forIndexPath:indexPath];
            NSDictionary *dict=dataArray[indexPath.row];
            JokesCell.Jokes = [dict valueForKey:@"detail"];
            [JokesCell.JokesTableView reloadData];
            return JokesCell;
        }
        return JokesCell;
    }
    else
    {

    }
    return nil;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = dataArray[indexPath.row];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath];
    if([dict[@"type"] isEqual:@"Traffic" ])
    {
        //Find your collectionView in cell
        //Tap on Traffic cells
    }
    else if([dict[@"type"] isEqual:@"News"])
    {
        //Tap on News cells

    }
    else if([dict[@"type"] isEqual:@"Category"])
    {
        //Tap on Category cells

    }
    else if([dict[@"type"] isEqual:@"TopApps"])
    {
        //Tap on TopApps cells

    }
    else if([dict[@"type"] isEqual:@"TopSites"])
    {
        //Tap on TopSites cells

    }
    else if([dict[@"type"] isEqual:@"TrendingVideos"])
    {
        //Tap on Trending cells

    }
    else if([dict[@"type"] isEqual:@"Sports"])
    {
        //Tap on Sports cells

    }
    else if([dict[@"type"] isEqual:@"Jokes"])
    {
        //Tap on Jokes cells
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict = dataArray[indexPath.row];
    if([dict[@"type"] isEqual:@"Traffic" ])
    {
        return 155;
    }
    else if([dict[@"type"] isEqual:@"News"])
    {
        return 300;
    }
    else if([dict[@"type"] isEqual:@"Category"])
    {
        return 120;
    }
    else if([dict[@"type"] isEqual:@"TopApps"])
    {
        return 180;
    }
    else if([dict[@"type"] isEqual:@"TopSites"])
    {
        return 240;
    }
    else if([dict[@"type"] isEqual:@"TrendingVideos"])
    {
        return 270;
    }
    else if([dict[@"type"] isEqual:@"Sports"])
    {
        return 310;
    }
    else if ([dict[@"type"] isEqual:@"Jokes"])
    {
        return 280;
    }
    return 200;
}
于 2016-09-13T07:17:05.510 に答える