How to handle didSelectRowAtIndexPath so that it works on all the three different cell for each cell in it?
Preview
Flow of my code
- (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(!CategoryCell)
{
CategoryCell= [tableView dequeueReusableCellWithIdentifier:#"CategoryTableViewCell" forIndexPath:indexPath];
NSDictionary *dict=dataArray[indexPath.row];
CategoryCell.Category = [dict valueForKey:#"detail"];
[CategoryCell.CategorycollectionView reloadData];
return CategoryCell;
}
return CategoryCell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
You can handle tap on UITableViewCell the same as you implement in cellForRowAtIndexPath method
- (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 {
//Tap on other cells
}
}
And in cellForRowAtIndexPath you need
TrafficCell.collectionView.delegate = self;
CategoryCell.CategorycollectionView.delegate = self;
for handle tap on UICollectionViewCell and implement UICollectionViewDelegate method
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
//Tapped on your collectionViewCell inside the uitableviewcell
}
I have a table view and now I'm initialising the table like,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [arr count]+1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr count]+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0)
{
UITableViewCell *cell = [[UITableViewCell alloc] init];
return cell;
}
else
{
static NSString *CellIdentifier = #"moduleCell";
MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"MyTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#""]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
current = [arr objectAtIndex:indexPath.row-1];
[cell setCellDetails:arr WithIndex:row-1 withParentView:self];
return cell;
}
}
When I'm doing this data repeating in my tableview. Before I do this, I did,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
This is working but I need to set section headers like titles. So is there a way to set section headers without repeating data?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0){//for first section
}else if(indexPath.section == 1){//for second section
}
}
You need to implement this method:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section==0) {
return "name";
}else{
//
}
}
You need to keep heading in Array. So, you can avoid hardcoded in the delegate method.
NSArray *heading=#[#"Today",#"Yesterday",#"Tomorrow"];
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *heading = [heading objectAtIndex:section]; //
return heading;
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
var cstmView:UIView!
let lbl:UILabel
cstmView = UIView()
cstmView.frame = CGRectMake(0,0,tableView.contentSize.width,70.0)
let logo:UIImageView = UIImageView();
logo.image = UIImage(named: "logo_with_lightGrayColor")
logo.frame = CGRectMake(8.0,10.0,200.0,60.0)
lbl = UILabel()
lbl.frame = CGRectMake(8.0,80.0,200.0,20.0)
lbl.text = "USER NAME"
lbl.textColor = UIColor.whiteColor()
lbl.font = UIFont.systemFontOfSize(15.0)
cstmView .addSubview(logo)
cstmView.addSubview(lbl)
return cstmView;
}
You should implement custom header for tableview.
In my table view I've two sections with different custom cell for both section.I want to select one row from each section.Is it possible?
Here is my approach -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.section == 0) {
static NSString *CellIdentifier = #"categoryCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ReportCategoryCell* catCell = (ReportCategoryCell *)cell;
if (indexPath == selectedCategoryIndexPath)
{
catCell.selected = YES;
}
else
{
catCell.selected = NO;
}
catCell.categoryLabel.text = [categories objectAtIndex:indexPath.row];
}
else
{
static NSString *CellIdentifier = #"durationCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ReportDurationCell* durationCell = (ReportDurationCell *)cell;
if (indexPath == selectedDurationIndexPath) {
durationCell.selected = YES;
}
else
{
durationCell.selected = NO;
}
durationCell.reportDurtionLabel.text = [durations objectAtIndex:indexPath.row];
}
cell.backgroundColor = [UIColor colorWithRed:88/255.0 green:55/255.0 blue:175/255.0 alpha:1.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
and
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
selectedCategoryIndexPath = indexPath;
}
else
{
selectedDurationIndexPath = indexPath;
}
}
But it select only one row from either section(i want to select one row from each section).also i need first row of each section selected by default.
Add a bool property in your custom cell's header files. and make following changes (Assuming that you have initialised selectedCategoryIndexPath and selectedDurationIndexPath appropriately) -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.section == 0) {
static NSString *CellIdentifier = #"categoryCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ReportCategoryCell* catCell = (ReportCategoryCell *)cell;
if (indexPath.row == selectedCategoryIndexPath.row) {
catCell.isSelected = YES;
}
else
catCell.isSelected = NO;
catCell.categoryLabel.text = [categories objectAtIndex:indexPath.row];
catCell.backgroundColor = [UIColor colorWithRed:88/255.0 green:55/255.0 blue:175/255.0 alpha:1.0];
catCell.selectionStyle = UITableViewCellSelectionStyleNone;
return catCell;
}
else
{
static NSString *CellIdentifier = #"durationCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ReportDurationCell* durationCell = (ReportDurationCell *)cell;
if (indexPath.row == selectedDurationIndexPath.row) {
durationCell.isSelected = YES;
}
else
durationCell.isSelected = NO;
durationCell.reportDurtionLabel.text = [durations objectAtIndex:indexPath.row];
durationCell.backgroundColor = [UIColor colorWithRed:88/255.0 green:55/255.0 blue:175/255.0 alpha:1.0];
durationCell.selectionStyle = UITableViewCellSelectionStyleNone;
return durationCell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
selectedCategoryIndexPath = indexPath;
}
else
{
selectedDurationIndexPath = indexPath;
}
[self.tableView reloadData];
}
I have a UITableView that serves as a menu (user picks a row and fires a segue). Currently my code looks like:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self isAuthorized]) {
if ([self isAdmin]) {
return 7;
}
return 5;
} else {
return 4;
}
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self isAuthorized]) {
if ([self isAdmin]) {
if (indexPath.row == 0) {
// code 1
} else (indexPath.row == 1) { {
// code 2
} // etc...
} else {
if (indexPath.row == 0) {
// code 1
} else (indexPath.row == 1) { {
// code 2
} // etc...
}
} else {
if (indexPath.row == 0) {
// code 1
} else (indexPath.row == 1) { {
// code 2
} // etc...
}
}
is it possible to tie action initiated by cell with a cell, so didSelectRowAtIndexPath looks simplier?
You could create your custom UITableViewCell classes and try doing the following:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
id cell = [tableView cellForRowAtIndexPath: indexPath];
if ([cell isKindOfClass: [AdminCellClass class]])
{
//code here
}
else if
...
}
Hear is just the idea what i am thinking to implement this,
I want to implement book like pages, for this i want to take UITableView and rotated-90 degree and its cell by 90 degree, and now i want to subclass UITableViewCell, now within this tableview cell it is possible to add UITableview so that user can scroll vertically to see the contents and user can also scroll horizontally to go to next cell of rotated tableview.
It is just i am thinking, is there any better way to implement this.
yes it is possible, I added the UITableVIew within the UITableView cell
.. :)
no need to add tableview cell in xib file - just subclass the UITableviewCell and use the code below, a cell will be created programatically.
//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 version
Create a single view project add tableview inside storyboard and set up its datasource and delegate
Paste code below to 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
}
}
create a new file CustomCell.swift which is the subclass of UITableViewCell and do not select with xib this file is without .xib file table and its cell will be created programatically as in objective-c code.
Paste code below to 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!
}
}
Better way: use a UIPageViewController for your left/right page scrolling. Each page can contain a table view.
Although rob's Idea is better but yes it is possible. Check how:
Take 2 table view, give them tag 1, 2, let's call these kTagBaseTableView, kTagInnerTableView. Now below is the blue print, how to deat with two table view, with delegate and data source attached to single view controller.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ // Default is 1 if not implemented
switch (tableView.tag) {
case kTagBaseTableView:
return baseSectionCount;
break;
case kTagInnerTableView:
return innerSectionCount;
break;
default:
break;
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
switch (tableView.tag) {
case kTagBaseTableView:
return [baseDataSource count];
break;
case kTagInnerTableView:
return [innerDataSource count];
break;
default:
break;
}
return 0;
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
switch (tableView.tag) {
case kTagBaseTableView:{
static NSString* baseIdentifier = #"baseTableViewCell";
cell = [tableView dequeueReusableCellWithIdentifier:genderIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:genderIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
cell.textLabel.text = NSLocalizedString(titleKey, nil);
return cell;
}
break;
case kTagInnerTableView:{
static NSString* innerIdentifier = #"innerTableViewCell";
cell = [tableView dequeueReusableCellWithIdentifier:genderIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:genderIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
cell.textLabel.text = NSLocalizedString(titleKey, nil);
return cell;
}
default:
break;
}
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ // fixed font style. use custom view (UILabel) if you want something different
switch (tableView.tag) {
case kTagBaseTableView:
break;
case kTagInnerTableView:
break;
default:
break;
}
return nil;
}
//TABLE VIEW DELEGATE
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
selectedIndexPath = indexPath;
switch (tableView.tag) {
case kTagBaseTableView:{}
break;
case kTagInnerTableView:{
}
break;
default:
break;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Create a subclass for tableView and override the intrinsicContentSize. I have answered here.
#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;
}