Found The solution with help of #parcs and #payal- This link helped -> http://www.appcoda.com/customize-table-view-cells-for-uitableview/
Basically , the table view lags when i scroll, i have gone through many post but it didn't help-
UITableView in UIScrollview scrolling delay
Delayed UIImageView Rendering in UITableView
slow scrolling of UITableView
UITableView lags while scrolling
This is the code , which i am using in cellForRowIndexpath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"WorkoutCell";
WorkoutCell *cell = (WorkoutCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
UIViewController *controller=[[UIViewController alloc] initWithNibName:CellIdentifier bundle:nil];
cell=(WorkoutCell *)controller.view;
}
[[cell contentView] setBackgroundColor:[UIColor clearColor]];
[[cell backgroundView] setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//diplaying Workout Data
[cell setupFont];
cell.lblPoint.text=[NSString stringWithFormat:#"%#",[[arrTblData objectAtIndex:indexPath.row]valueForKey:#"point"]];
cell.lblReps.text=[[arrTblData objectAtIndex:indexPath.row]valueForKey:#"reps"];
cell.lblWorkoutCategory.text=[[arrTblData objectAtIndex:indexPath.row]valueForKey:#"workout"];
cell.lblWeight.text=[[arrTblData objectAtIndex:indexPath.row]valueForKey:#"weight"];
cell.lblSets.text=[[arrTblData objectAtIndex:indexPath.row]valueForKey:#"sets"];
//Formatting Date
cell.lblPostedDate.text=[NSString stringWithFormat:#"Posted On: %#",[self formatDate:[[arrTblData objectAtIndex:indexPath.row]valueForKey:#"time"]]];
return cell;
}
The Function SetupFont called from cellForRowIndexpath
-
(void)setupFont
{
self.lblPoint.font=DEFAULT_FONT(13);
self.pointLblScreen.font=DEFAULT_FONT(13);
self.lblPostedDate.font=DEFAULT_FONT(13);
self.lblReps.font=DEFAULT_FONT(13);
self.lblSets.font=DEFAULT_FONT(13);
self.lblWeight.font=DEFAULT_FONT(13);
self.lblWorkoutCategory.font=DEFAULT_FONT(18);
self.lblWorkoutCategory.strokeColor=kStrokeColor2;
self.lblWorkoutCategory.strokeSize = kStrokeBigSize;
for(UILabel *lbl in [self subviews])
{
if(lbl.tag==9)
{
lbl.font=DEFAULT_FONT(13);
}
}
}
Format Date Function called from cellForRowIndexpath
#pragma mark - Format Date Function
-(NSMutableString*)formatDate:(NSString*)date
{
NSMutableString *formattedDate=[[NSMutableString alloc]init];
NSUInteger p = 0;
NSUInteger length = [date length];
while ( p < length) {
unichar ch = [date characterAtIndex: p];
if (ch!=' ')
{
if(ch=='-')
{
ch='/';
}
NSString *appendString = [NSString stringWithFormat:#"%c",ch];
[formattedDate appendString:appendString];
p++;
}
else
{
break;
}
}
return formattedDate;
}
This is not the right way to do this:
WorkoutCell *cell = (WorkoutCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
UIViewController *controller=[[UIViewController alloc] initWithNibName:CellIdentifier bundle:nil];
cell=(WorkoutCell *)controller.view;
}
Instead of this, subclass UITableViewCell and instantiate that cell here as follows:
WorkoutCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"WorkoutCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
Also, move your setupFont method the UITableViewCell subclass.
You are typecasting the UIViewController to UITableviewCell.Instead of that take UITableViewCell class add the outlets whatever you want and use it
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle]loadNibNamed:#"CustomCell" owner:nil options:nil] objectAtIndex:0];
}
// access that CustomCell variables here
cell.name.text = #"Name";
}
You use
#interface WorkoutCell : UITableViewCell {}
then table view class
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString * const CellIdentifier = #"WorkoutCell";
WorkoutCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if( !cell )
{
cell = [[WorkoutCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];
}
}
Related
was working in Xcode 4.6 and have a UItableview set up where the cells are populated from an array. When working in 4.6, the view behaved perfectly and was just how I liked it. After the update to 5.1.1, scrolling seems to have been enabled on the table view, the table view is loaded from the bottom of the view and the 3 populated cells at the top are not visible. Sometimes the view will rubber band and not allow me to scroll all the way back up to the top, and sometimes it won't rubber band and will let me. I am fairly new to this, but have tried messing around with auto layout, but to no avail.
Here's my code for the .h
#interface TableViewController : UITableViewController
#property (nonatomic, strong) NSArray *Manufacturers;
#end
Here's my code for the .m:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_Manufacturers = #[#"1",
#"2",
#"3"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _Manufacturers.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
int row = [indexPath row];
cell.TitleLabel.text = _Manufacturers[row];
return cell;
}
In cellForRowAtIndexPath:
If you are using default UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableCell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CellIdentifier"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyIdentifier"];
}
int row = [indexPath row];
cell.textLabel.text = _Manufacturers[row];
return cell;
}
If you are using custom TableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
TableCell is Custom than write below code..
TableCell *cell = (TableCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"TableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
Otherwise
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
Look at this tutorial for custom cell
http://www.appcoda.com/customize-table-view-cells-for-uitableview/
I have a Tableview and i am using the customTableview cell for displaying the cell
in the cell i have 5 buttons (rating buttons) when i click on particular button the image of the button has to changed its working fine but when i am scrolling the tableview again thay are changing to normal rating buttons see the following images for clarity
This is the image before scrolling and clicking nothing on button
after clicking the on rating buttons the image is changing like this
but when scrolling the cells again its changing to first image
please help me out
Code :
- (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
dataCell = (DataCel)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (dataCell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"DataCel" owner:self options:nil]; dataCell = [nib objectAtIndex:0];
}
return dataCell;
}
you should save the sate of the button images
and in your
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
insert code to keep them updated
for ex:
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//create your cell here if it was not created
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
[cell.textLabel setFont:[UIFont boldSystemFontOfSize:13]];
[cell.textLabel setTextColor:[UIColor darkGrayColor]];
[cell.detailTextLabel setFont:[UIFont boldSystemFontOfSize:11]];
[cell.detailTextLabel setTextColor:[UIColor lightGrayColor]];
cell.detailTextLabel.numberOfLines = 2;
}
NSArray *array = [imageArray objectAtIndex:[indexPath row]];
if([[array objectAtIndex:3] isEqual:#"rate3"])
{
//set the code for the rating 3
}
else
{
//insert another rate depending on your object
}
This is because every time you scroll the UITableView, it refreshes its values from the data you provided it ! So the value is not retained. To prevent this from happening every time you scroll the database you can use this
static NSString *cellIdentifier = #"Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
}
for(id obj in cell.contentView.subviews)
{
if([obj isKindOfClass:[UIImageView class]] || [obj isKindOfClass:[UILabel class]])
{
[obj removeFromSuperview];
}
}
This would not let the values be overlapped.
When scrolled the cells are recreated and so you need the keep the selected values in a seperate array and set it in the cellForRowAtIndexPath method
This happens because every time you scroll the tableview , it re-create tableview cell. therefor you can use array for reused it.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = #"cellId";
UITableViewCell *cell = [categoriesTableview dequeueReusableCellWithIdentifier:cellId];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
// ui goes here
return cell
}
I want to design a tableview such that each cell has a different background image depending on a condition. There are 10 images for cell background and I want to load them as such that the image pattern is repeated on the cells. For example, cells 1-10 take images from 1-10 respectively. Then cells 11-20 also take images 1-10 and so on. How can I achieve this?
give image name like: images_1/2.../10.png
//write it
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell1";
CustomCell *Cell = (CustomCell *)[tabeleYourTurn dequeueReusableCellWithIdentifier:CellIdentifier];
if (Cell == nil)
{
NSArray *topLevelObject= [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
}
for (id currentobject in topLevelObject)
{
if ([currentobject isKindOfClass:[UITableViewCell class]])
{
Cell = (CustomCell *) currentobject;
break;
}
}
}
NSString *image = [NSString stringWithFormat:#"images_%d.png", indexPath.row % 10 + 1];
Cell.imageView.image = [UIImage imageNamed:image];
return Cell;
}
May be it will work.
First create an array with ImageName..
Like
NSArray *ImageArray=[[NSArray alloc]initWithObjects:#"1.png",#"2.png"];
Then this array with 10 images
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// create a background image for the cell:
UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectZero];
[cell setBackgroundColor:[UIColor clearColor]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setBackgroundView:bgView];
[cell setIndentationWidth:0.0];
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:[ImageArray objectAtIndex:indexPath.row%10]];
}
Assuming that your image names are 1, 2...10, you can try to do something like this:
NSString *imageName = [NSString stringWithFormat:#"%d", indexPath.row % 10 + 1];
Than you can use this imageName where you want.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if( (indexPath.row % 10 ) <= 1)
{
// set your image
cell.imageView.image = [UIImage imageNamed:#"image1.png"];
}
}
I've a custom UITableViewCell subclass and I've read that this is supposed to be the correct way of loading custom cells for iOS 5:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tv dequeueReusableCellWithIdentifier:#"customCell"];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"customCell"];
// Configure cell
cell.nameLabel.text = self.customClass.name;
}
return cell;
}
But the label text is not shown when I run the app. However, I also tried this way:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:#"customCell"];
if (cell == nil) {
NSArray* views = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:nil options:nil];
for (UIView *view in views) {
if([view isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *)view;
}
}
// Configure cell
((CustomCell *)cell).nameLabel.text = self.customClass.name;
}
return cell;
}
This way the label is displayed, but any reuseIdentifier is set in loadNibName: method. What the best way of loading custom cells should be? I need to support iOS 5+. Could the first approach not be working because I'd to configure cell's labels and styles in initWithStyle: method and not in the table view's method?
Thanks!
The error in your code is that cell.nameLabel.text is only set in the if (cell == nil) { ... } case and not generally.
The easiest ways to load custom cells are
Use registerNib:forCellReuseIdentifier: if the cell is defined in a nib file, or
use registerClass:forCellReuseIdentifier: if the cell is created programmatically, or
use a Storyboard and define "CustomCell" as "Prototype Cell" for the table view.
For example (in viewDidLoad):
[self.tableView registerNib:[UINib nibWithNibName:#"CustomCell" bundle:nil] forCellReuseIdentifier:#"customCell"];
Then dequeueReusableCellWithIdentifier
will always return a cell, so that cellForRowAtIndexPath simplifies to
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tv dequeueReusableCellWithIdentifier:#"customCell"];
cell.nameLabel.text = self.customClass.name;
return cell;
}
Just use this code and try.
static NSString *cellIdentifier=#"cell";
YourCustomCell *cell = (YourCustomCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSString *customeCellName = [NSString stringWithFormat:#"%#",[YourCustomCell class]];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:customeCellName owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (YourCustomCell *) currentObject;
break;
}
}
}
cell.nameLabel.text = self.customClass.name; // Make sure self.customclass.name have value.
return cell;
Use this code (NewCustomCell is your Custom UITableViewCell class name)...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
NewCustomCell *cell = (NewCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:#"NewCustomCell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
return cell;
}
Happy coding... :)
I am trying to put a cell as a space between each cell - which will be hidden by setting alpha = 0. In my table, the space cells will be for rows that are odd.
Note that the actual cell height is 85, but the hidden cell height (ie space between cells) is 20.
The problem is that the space cell height is 85, but not 20, I don't know why. Maybe the cell is not loaded correctly.
Cell here is the UITableViewCell - the actual cell - with identifier 'Cell'.
Cell2 is the space with identifier 'Space'.
Each class above has its own UITableViewCell class and the XIB files are also assigned to each of them. The identifier is also set in the IB for each Xib.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier1 = #"Cell";
static NSString *CellIdentifier2 = #"Space";
Cell *cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if(!cell)
{
NSArray *ar = [[NSBundle mainBundle] loadNibNamed:#"CellView" owner:nil options:nil];
for (id obj in ar)
{
if ([obj isKindOfClass:[Cell class]])
{
cell = (Cell *)obj;
break;
}
}
}
if (indexPath.row % 2 == 1)
{
Cell2 *cell2 = (Cell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (!cell2)
{
NSArray *ar = [[NSBundle mainBundle] loadNibNamed:#"Cell2" owner:nil options:nil];
for(id obj in ar)
{
if([obj isKindOfClass:[Cell2 class]])
{
cell2 = (Cell2 *)obj;
break;
}
}
// Method 1
cell2 = [[Cell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
// Method 2
//cell2 = [[Cell2 alloc] init];
// Method 3
//cell2 = (Cell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
[cell2.contentView setAlpha:0];
// prevent selection and other stuff
[cell2 setUserInteractionEnabled:NO];
}
return cell2;
}
else
{
// Configure the actual cell
}
return cell;
}
* I've renamed some of your NIB/Class names for a better understanding. *
First, you should register each cells' NIB:
- (void)viewDidLoad{
[super viewDidLoad];
static NSString *CellIdentifier1 = #"ContentCell";
static NSString *CellIdentifier2 = #"SpaceCell";
UINib *nib = [UINib nibWithNibName:#"CellViewNIBName" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier1];
nib = [UINib nibWithNibName:#"CellSpaceNIBName" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier2];
self.contentView.hidden = YES;
[self loadData];
}
Because you have the NIBs registered, dequeueReusableCellWithIdentifier: will always return a cell:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier1 = #"ContentCell";
static NSString *CellIdentifier2 = #"SpaceCell";
// Space Cell
if (indexPath.row % 2 == 1) {
CellSpace *cell = (CellSpace *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
return cell;
}
// Content cell
else {
CellView *cell = (CellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
// Configure cell
return cell;
}
}
Last, but not least, make sure to implement the following delegate method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Space cell's height
if (indexPath.row % 2 == 1) {
return 20.0f;
}
// Content cell's height
else {
return 80.0f;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *returncell;
static NSString *cellIdentifier ;
if(indexPath.section == 0)
{
cellIdentifier = #"cell1";
}
else if (indexPath.section == 1)
{
cellIdentifier = #"cell2";
}
UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
MapTableViewCell *myCustomCell = (MapTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(indexPath.section == 0)
{
if(myCell == nil)
{
myCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
getLocationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
getLocationBtn.frame = CGRectMake(myCell.frame.origin.x,myCell.frame.origin.y+5 , 200, 30);
[getLocationBtn setTitle:#"your button title" forState:UIControlStateNormal];
[getLocationBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[getLocationBtn addTarget:self action:#selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
}
[myCell.contentView addSubview:getLocationBtn];
returncell = myCell;
}
else if (indexPath.section == 1)
{
if (myCustomCell == nil)
{
myCustomCell = [[MapTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
myCustomCell.nearbyLocation.text = #"demo Text";
returncell = myCustomCell;
}
return returncell;
}
//mycustom tablviewcell
import "MapTableViewCell.h"
#implementation MapTableViewCell
#synthesize nearbyLocation;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if(self)
{
self.backgroundColor = [UIColor groupTableViewBackgroundColor];
nearbyLocation = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 30)];
[self addSubview:nearbyLocation];
}
return self;
}
#end
Best way to use number of custom cells with default cell
In addition for the answers provided, I want to emphasize on the Cell Identifier for each different custom cells must be different too.
For example custom cellA with identifier "Cell" and custom cellB with identifier "Cell2".