I have the following requirement to display data in a tableView as follows:
POST
POST
POST
CHANNEL CHANNEL CHANNEL ...(Each row has 6 channels)
POST
POST
POST
CHANNEL CHANNEL CHANNEL .....
For clarification, see the below image:

For example, if posts count = 20 and channels count = 2
then we have to display like this:
POST
POST
POST
CHANNEL CHANNEL
POST
POST
....
Is it possible to implement this way in Objective- C using Switch statement or any other way without conflicts?
Easiest way is to use CollectionView inside TableView. This means that you should have UITableviewCells to represent each posts and for channels you should have a UITableViewCell with CollectionView inside. This UITableViewCell cell will implement CollectionView Delegates.
For example, if posts count = 20 and channels count = 2
then you have to display like this:
POST - UITableViewCell
POST - UITableViewCell
POST - UITableViewCell
CHANNELS -> UITableViewCell ->
[channel1 channel2] -> UICollectionViewCell
POST - UITableViewCell
POST - UITableViewCell
UITableView[
UITableViewCell -> Post UI
UITableViewCell -> Post UI
UITableViewCell -> Post UI
UITableViewCell -> CollectionView[
UICollectionViewCell ->Channel1 UI
UICollectionViewCell ->Channel2 UI
]
]
You don't have to use switch case here. You need a property which is used to differentiate Posts and channels
UITableViewCell *cell = nil;
if (data.type == DATA_TYPE_POST){
cell = [tableView dequeueReusableCellWithIdentifier:PostCellIdentifier];
if(!cell){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PostCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
}else{
cell = [tableView dequeueReusableCellWithIdentifier:ChannelCellIdentifier];
if(!cell){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChannelCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With