How to create UITableView programmatically - ios

I have the following code to create a view with a table programmatically
- (void) createView:(UIViewController*)viewController{
_thisViewController = viewController;
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = #"Title";
titleLabel.frame = CGRectMake(75, 20, 200, 50);
titleLabel.textColor = [UIColor blackColor];
titleLabel.font = [titleLabel.font fontWithSize: 24];
UILabel *subtitleLabel = [[UILabel alloc] init];
subtitleLabel.text = #"Subtitle";
subtitleLabel.frame = CGRectMake(75, 50, 400, 50);
subtitleLabel.textColor = [UIColor blackColor];
subtitleLabel.font = [subtitleLabel.font fontWithSize: 20];
UILabel *labelStatus = [[UILabel alloc] init];
labelStatus.text = #"";
labelStatus.frame = CGRectMake(75, screenHeight - 290, 500, 50);
labelStatus.textColor = [UIColor blueColor];
labelStatus.font = [labelStatus.font fontWithSize: 20];
UITableView *tableDeviceList = [[UITableView alloc] init];
tableDeviceList.frame = CGRectMake(75, 100, screenWidth -250, screenHeight - 400);
tableDeviceList.dataSource = self;
tableDeviceList.delegate = self;
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
[cancelButton setTitle:#"Cancelar" forState:UIControlStateNormal];
[cancelButton sizeToFit];
cancelButton.frame = CGRectMake((screenWidth/2)-100, screenHeight - 250, 100, 50);
cancelButton.backgroundColor = UIColorFromRGB(0x066D8B);
cancelButton.layer.cornerRadius = 20;
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cancelButton addTarget:self action:#selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIViewController *viewControllerModal = [[UIViewController alloc] init];
UIView *nooView = [[UIView alloc] initWithFrame:CGRectMake(50, 80, screenWidth - 100, screenHeight - 160)];
nooView.backgroundColor = UIColorFromRGB(0xE8E8E8);
nooView.layer.cornerRadius = 20;
[nooView addSubview:titleLabel];
[nooView addSubview:subtitleLabel];
[nooView addSubview:tableDeviceList];
[nooView addSubview:labelStatus];
[nooView addSubview:cancelButton];
[viewControllerModal.view addSubview:nooView];
[viewController presentViewController: viewControllerModal animated:YES completion:nil];
}
Which is throwing me an error of tableView:numberOfRowsInSection:, so I wonder if is there a way to add a function to a UITableView created this way (I'm creating my UITableView programmatically).
Also, my class is of type NSObject, so I wonder if there will be a problem with the assignment of the dataSource and delegate properties of the tableDeviceList.

You need to implement the dataSource and delegate methods of UITableView in your class,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; // number of sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10; // should be your array count
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.textlabel.text = #"test";
return cell;
}

Firstly, you should set the following:
UITableView(your tableview name).delegate = self;
UITableView(your tableview name).dataSource = self;
Secondly, you need to implement the delegate methods and datasource methods
such as:

Related

Add loading footer on UITableView

I have a UITableView. When I scroll to the bottom it loads more data. How can I add a loading animation to the footer of the table when it´s scrolled to the bottom?
You can use MNMBottomPullToRefreshManager file to load more data. First you have to initialize it in viewDidLoad as
pullToRefreshManager_ = [[MNMBottomPullToRefreshManager alloc] initWithPullToRefreshViewHeight:60.0f tableView:table withClient:self];
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[pullToRefreshManager_ tableViewScrolled];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate
{
[pullToRefreshManager_ tableViewReleased];
}
- (void)bottomPullToRefreshTriggered:(MNMBottomPullToRefreshManager *)manager
{
//method to get more data
// [self CallWebServiceToLoadMorePAYMENTS];
}
}
After reloading your tableView call:
[pullToRefreshManager_ tableViewReloadFinished];
Try this
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *headerView = [[[UIView alloc] init]autorelease];
[headerView setBackgroundColor:[UIColor clearColor]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Load More" forState:UIControlStateNormal];
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0);
[headerView addSubview:button];
return headerView;
}
Use this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if(array.count>1){
if(indexPath.row == array.count-1){
[self setupTableViewFooter];
}
}
}
- (void)setupTableViewFooter
{
// set up label
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
footerView.backgroundColor = [UIColor clearColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:Font_MuseoSans size:14];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.textColor = [UIColor darkGrayColor];
label.text = #"Loading";
self.footerLabel = label;
CGSize labelSize = [self.footerLabel sizeThatFits:footerView.frame.size];
[footerView addSubview:self.footerLabel];
// set up activity indicator
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.hidesWhenStopped = YES;
activityIndicatorView.color = [UIColor blackColor];
self.activityIndicator = activityIndicatorView;
[self.activityIndicator startAnimating];
[footerView addSubview:self.activityIndicator];
CGRect footerFrame = footerView.frame;
label.frame = CGRectMake((footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width)/2, (footerFrame.size.height-labelSize.height)/2
, (footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width), labelSize.height);
self.activityIndicator.frame = CGRectMake(label.frame.origin.x + labelSize.width + 4, (footerFrame.size.height-activityIndicatorView.frame.size.height)/2
, activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);
self.tableView.tableFooterView = footerView;
}

UITableView's footer is not visible while scrolling

I have a scenario where my Table holds list of products. This list has a footerView with a button added to the footerView. I could able to see/scroll complete footerView along with the button when I open the already created Product List. But I cannot see complete button in the footerView when I create & Save the Product list for the first time.
I am using below code:
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_SIZE_WIDTH, 44)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10, 0, SCREEN_SIZE_WIDTH - 20, 44);
[footerView addSubview:button];
self.tableView.tableFooterView = footerView;
[self.tableView setTableFooterView:footerView];//Tried this one too
Please help me to show/scroll the button in footerView. Thanks!
Use this code, its working fine for me:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if(array.count>1){
if(indexPath.row == array.count-1){
[self setupTableViewFooter];
}
}
}
- (void)setupTableViewFooter
{
// set up label
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
footerView.backgroundColor = [UIColor clearColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:Font_MuseoSans size:14];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.textColor = [UIColor darkGrayColor];
label.text = #"Loading";
self.footerLabel = label;
CGSize labelSize = [self.footerLabel sizeThatFits:footerView.frame.size];
[footerView addSubview:self.footerLabel];
// set up activity indicator
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.hidesWhenStopped = YES;
activityIndicatorView.color = [UIColor blackColor];
self.activityIndicator = activityIndicatorView;
[self.activityIndicator startAnimating];
[footerView addSubview:self.activityIndicator];
CGRect footerFrame = footerView.frame;
label.frame = CGRectMake((footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width)/2, (footerFrame.size.height-labelSize.height)/2
, (footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width), labelSize.height);
self.activityIndicator.frame = CGRectMake(label.frame.origin.x + labelSize.width + 4, (footerFrame.size.height-activityIndicatorView.frame.size.height)/2
, activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);
self.tableView.tableFooterView = footerView;
}

cellForRowAtIndexPath and sizeToFit reduces label width when scrolling

I've a custom cell with labels init in a UITableViewCell.
In my cellForRowAtIndexPath method after setting label content i call sizeToFit on the label to get the correct width and height, but when i scroll in my TableView, the label width reduce on each cells, every time i scroll.
Anyone for help ?
Thanks
My custom UITableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
CGRect viewBounds = self.contentView.bounds;
// marge
CGFloat margin = 20;
self.excuse_date = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, 300, 30)];
self.excuse_date.textColor = [UIColor blackColor];
self.excuse_date.font = [UIFont fontWithName:#"Arial" size:12.0f];
[self addSubview:self.excuse_date];
static CGFloat dateWidth = 130;
self.excuse_date.frame = CGRectMake(viewBounds.size.width-dateWidth-35, margin, dateWidth, 20);
CGRect dateFrame = self.excuse_date.frame;
self.excuse_date.textAlignment = NSTextAlignmentRight;
// setup excuse_auteur
self.excuse_auteur = [[UILabel alloc] init];
self.excuse_auteur.font = [UIFont fontWithName:#"Helvetica" size:13];
self.excuse_auteur.textColor = [UIColor darkGrayColor];
self.excuse_auteur.textAlignment = NSTextAlignmentLeft;
self.excuse_auteur.frame = CGRectMake(margin, margin, viewBounds.size.width-dateWidth-(margin*2), 20);
[self addSubview:self.excuse_auteur];
// setup excuse_texte
self.excuse_texte = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(dateFrame)+margin/2, viewBounds.size.width - (margin*3), 200)];
self.excuse_texte.lineBreakMode = NSLineBreakByWordWrapping;
self.excuse_texte.numberOfLines = 0;
self.excuse_texte.font = [UIFont fontWithName:#"Helvetica" size:17];
self.excuse_texte.autoresizingMask = UIViewAutoresizingNone;
[self addSubview:self.excuse_texte];
CGRect textFrame = self.excuse_texte.frame;
// setup up image
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"up-small"]];
self.img = imageView;
[self addSubview:self.img];
imageView.frame = CGRectMake(20, CGRectGetMaxY(textFrame)+margin/2, 20, 20);
// setup up
self.up = [[UILabel alloc] initWithFrame:CGRectMake(45, CGRectGetMaxY(textFrame)+margin/2+2, viewBounds.size.width - margin*2, 20)];
self.up.font = [UIFont fontWithName:#"Helvetica" size:11];
self.up.textColor = [UIColor darkGrayColor];
self.up.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.up];
}
return self;
}
My cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BBExcuse *excuse = [self.list objectAtIndex:indexPath.row];
static NSString *cellIdentifier = #"Cell";
// Similar to UITableViewCell, but
BBTableViewCell *cell = (BBTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[BBTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.excuse_texte.text = excuse.excuse_texte;
// #TODO problem here ?
[cell.excuse_texte sizeToFit];
cell.excuse_auteur.text = excuse.excuse_auteur;
cell.excuse_date.text = excuse.excuse_date;
cell.up.text = [NSString stringWithFormat:#"%#", excuse.up];
cell.img.frame = CGRectMake(20, CGRectGetMaxY(cell.excuse_texte.frame)+20/2, 20, 20);
cell.up.frame = CGRectMake(45, CGRectGetMaxY(cell.excuse_texte.frame)+20/2+2, 20, 20);
// setup up
return cell;
}
Ok solved by removing sizeToFit and specify height and width in cellForRowAtIndexPath
cell.excuse_texte.text = excuse.excuse_texte;
NSString *str = excuse.excuse_texte;
UILabel *gettingSizeLabel = [[UILabel alloc] init];
gettingSizeLabel.font = [UIFont systemFontOfSize:17];
gettingSizeLabel.text = str;
gettingSizeLabel.numberOfLines = 0;
gettingSizeLabel.lineBreakMode = NSLineBreakByWordWrapping;
CGSize maximumLabelSize = CGSizeMake(260.0f, 9999.0f);
CGSize theSize = [gettingSizeLabel sizeThatFits:maximumLabelSize];
// on resize sans sizetofit
cell.excuse_texte.frame = CGRectMake(cell.excuse_texte.frame.origin.x, cell.excuse_texte.frame.origin.y, cell.excuse_texte.frame.size.width, theSize.height);

UiTableViewHeader - Dynamic button event handler

I need to add a uiButton to a static uitableview section header - I've made an attempt with the following -
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// you can get the title you statically defined in the storyboard
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
CGRect frame = tableView.bounds;
// create and return a custom view
#define LABEL_PADDING 10.0f
HeaderLabelStyling *customLabel = [[HeaderLabelStyling alloc] initWithFrame:CGRectInset(frame, LABEL_PADDING, 0)] ;
UIButton *addButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-60, 10, 50, 30)];
addButton.backgroundColor = [UIColor whiteColor];
addButton.titleLabel.textColor = [UIColor colorWithRed:240/255.0f green:118/255.0f blue:34/255.0f alpha:1.0f];
addButton.titleLabel.tintColor = [UIColor blackColor];
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
title.text = #"iawn";
customLabel.text = sectionTitle;
customLabel.backgroundColor= [UIColor colorWithRed:143.0f/255.0f green:137.0f/255.0f blue:135.0f/255.0f alpha:1.0f];
customLabel.textColor = [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
[customLabel addSubview:addButton];
[addButton addSubview:title];
[addButton addTarget:self action:#selector(receiverButtonClicked:) forControlEvents:UIControlEventTouchDown];
return customLabel;
}
-(void)receiverButtonClicked:(id)sender{
NSLog(#"button clicked");
}
the above adds a button - but doesn't react to the click event - can anyone suggest how I can get this to work?
UILabel does not handles touches by default.
Add following line of code:
customLabel.userInteractionsEnabled = YES;
In order to display button only for third section you should add following condition:
if(section == 2){...}
So your -tableView:viewForHeaderInSection: should look as follows:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection (NSInteger)section {
if(section != 2) return nil;
// you can get the title you statically defined in the storyboard
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
CGRect frame = tableView.bounds;
// create and return a custom view
#define LABEL_PADDING 10.0f
HeaderLabelStyling *customLabel = [[HeaderLabelStyling alloc] initWithFrame:CGRectInset(frame, LABEL_PADDING, 0)] ;
UIButton *addButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-60, 10, 50, 30)];
addButton.backgroundColor = [UIColor whiteColor];
addButton.titleLabel.textColor = [UIColor colorWithRed:240/255.0f green:118/255.0f blue:34/255.0f alpha:1.0f];
addButton.titleLabel.tintColor = [UIColor blackColor];
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
title.text = #"iawn";
customLabel.text = sectionTitle;
customLabel.backgroundColor= [UIColor colorWithRed:143.0f/255.0f green:137.0f/255.0f blue:135.0f/255.0f alpha:1.0f];
customLabel.userInteractionsEnabled = YES;
customLabel.textColor = [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:1.0f];
[customLabel addSubview:addButton];
[addButton addSubview:title];
[addButton addTarget:self action:#selector(receiverButtonClicked:) forControlEvents:UIControlEventTouchDown];
return customLabel;
}

Slow loading tableview on iPhone with reusable cells

I load the data from Parse.com backend, they send me a solutions for use the reusable cells but now I still have troubles with the loading speed, this is the coding I have in my tableview and I have a Subclass for making up my cells (ExploreStreamCustomCell.m)
- (ExploreStreamCustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = #"ExploreStreamCustomCell";
ExploreStreamCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ExploreStreamCustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.listItemTitle.text = [object objectForKey:#"text"];
cell.checkinsLabel.text = [NSString stringWithFormat:#"%#", [object objectForKey:#"checkins"]];
cell.descriptionLabel.text = [object objectForKey:#"description"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
PFFile *listThumbnail = [object objectForKey:#"header"];
cell.listViewImage.image = [UIImage imageNamed:#"loading_image_stream.png"]; // placeholder image
cell.listViewImage.file = listThumbnail;
[cell.listViewImage loadInBackground:NULL];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForNextPageAtIndexPath:indexPath];
cell.textLabel.font = [cell.textLabel.font fontWithSize:kPAWWallPostTableViewFontSize];
return cell;
}
If I have all the content of the //configure cell in the cell == nil the it's fast but it show up 3 of the 9 unique datarows and repeat those 3 unique content cell 3 times?
Edit extra code within ExploreStreamCustomCell.m
#import "ExploreStreamCustomCell.h"
#implementation ExploreStreamCustomCell
#synthesize listViewImage,
iconLocation,
iconPeople,
iconCheckins,
listItemTitle,
locationLabel,
peopleLabel,
checkinsLabel,
descriptionLabel,
listItemView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
//Initialization code
listItemView = [[UIView alloc] init];
listViewImage = [[PFImageView alloc] init];
iconLocation = [[UIImageView alloc] init];
iconPeople = [[UIImageView alloc] init];
iconCheckins = [[UIImageView alloc] init];
listItemTitle = [[UILabel alloc] init];
locationLabel = [[UILabel alloc] init];
peopleLabel = [[UILabel alloc] init];
checkinsLabel = [[UILabel alloc] init];
descriptionLabel = [[UILabel alloc] init];
listViewImage.image = [UIImage imageNamed:#"nachtwacht_list_formaat.png"];
iconLocation.image = [UIImage imageNamed:#"icon_magenta_location.png"];
iconPeople.image = [UIImage imageNamed:#"icon_magenta_people.png"];
iconCheckins.image = [UIImage imageNamed:#"icon_magenta_checkins.png"];
listItemTitle.text = #"text";
locationLabel.text = #"0,7 km";
peopleLabel.text = #"34";
checkinsLabel.text = #"61";
descriptionLabel.text = #"Description text.";
[self.contentView addSubview:listItemView];
[self.contentView addSubview:listViewImage];
[self.contentView addSubview:iconLocation];
[self.contentView addSubview:iconPeople];
[self.contentView addSubview:iconCheckins];
[self.contentView addSubview:listItemTitle];
[self.contentView addSubview:locationLabel];
[self.contentView addSubview:peopleLabel];
[self.contentView addSubview:checkinsLabel];
[self.contentView addSubview:descriptionLabel];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+0 , 33, 280, 124);
listViewImage.frame = frame;
listViewImage.contentMode = UIViewContentModeScaleAspectFill;
listViewImage.layer.masksToBounds = YES;
//listViewImage.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+20 , 164, 12, 18);
iconLocation.frame = frame;
//iconLocation.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+102 , 164, 24, 18);
iconPeople.frame = frame;
//iconPeople.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+193 , 164, 20, 16);
iconCheckins.frame = frame;
//iconLocation.backgroundColor = [UIColor lightGrayColor];
frame= CGRectMake(boundsX+0 , 0, 280, 33);
listItemView.frame = frame;
listItemView.backgroundColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
frame= CGRectMake(boundsX+20 , 3, 240, 29);
listItemTitle.frame = frame;
//listItemTitle.textColor = [UIColor colorWithRed:250.0f/255.0f green:194.0f/255.0f blue:9.0f/255.0f alpha:0.8f];
listItemTitle.textAlignment = UITextAlignmentLeft;
listItemTitle.font = [UIFont boldSystemFontOfSize:15];
listItemTitle.textColor = [UIColor whiteColor];
listItemTitle.backgroundColor = [UIColor clearColor];
listItemTitle.lineBreakMode = UILineBreakModeTailTruncation;
//listItemTitle.backgroundColor = [UIColor orangeColor];
frame= CGRectMake(boundsX+40 , 164, 57, 21);
locationLabel.frame = frame;
locationLabel.textAlignment = UITextAlignmentLeft;
locationLabel.font = [UIFont boldSystemFontOfSize:12];
locationLabel.textColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
locationLabel.backgroundColor = [UIColor clearColor];
locationLabel.lineBreakMode = UILineBreakModeTailTruncation;
locationLabel.numberOfLines = 1;
//locationLabel.backgroundColor = [UIColor redColor];
frame= CGRectMake(boundsX+134 , 164, 57, 21);
peopleLabel.frame = frame;
peopleLabel.textAlignment = UITextAlignmentLeft;
peopleLabel.font = [UIFont boldSystemFontOfSize:12];
peopleLabel.textColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
peopleLabel.backgroundColor = [UIColor clearColor];
peopleLabel.lineBreakMode = UILineBreakModeTailTruncation;
peopleLabel.numberOfLines = 1;
frame= CGRectMake(boundsX+221 , 164, 51, 21);
checkinsLabel.frame = frame;
checkinsLabel.textAlignment = UITextAlignmentLeft;
checkinsLabel.font = [UIFont boldSystemFontOfSize:12];
checkinsLabel.textColor = [UIColor colorWithRed:0.749 green:0.000 blue:0.243 alpha:1.000];
checkinsLabel.backgroundColor = [UIColor clearColor];
checkinsLabel.lineBreakMode = UILineBreakModeTailTruncation;
checkinsLabel.numberOfLines = 1;
frame= CGRectMake(boundsX+0 , 189, 280, 55);
descriptionLabel.frame = frame;
descriptionLabel.textAlignment = UITextAlignmentLeft;
descriptionLabel.font = [UIFont systemFontOfSize:13];
descriptionLabel.backgroundColor = [UIColor clearColor];
descriptionLabel.lineBreakMode = UILineBreakModeTailTruncation;
descriptionLabel.numberOfLines = 3;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
/*
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
A great way to explore the inefficiencies of your code is to use Instruments' Time Profiler tool. The Time Profiler will let you see how much time is being spent on each task, line-by-line in your code.
I would recommend the following settings for profiling:
From Apple's Face Detection sample app:
You can then double click any line (higher percentages mean more time is being devoted to that method call) to see in the code how much time is spent in each place.
From here you can begin to figure out where you are being inefficient and see exactly what is taking up so much time. Good luck!

Resources