Sponsors Ad

  

Inserting a full image background for UITableViewCell can bring down the scroll performance of your UITableView. Here is a useful code snippet to make UITableView scroll snappier.

Step 1. Create the background of dimensions of your UITableViewCell in Photoshop. Take a vertical slice of about 2 to 10 pixels of this image and save it as tablecellbackground.png and import it into your Xcode project

Step 2. In the TableView datasource method cellForRowAtIndexPath:(NSIndexPath *)indexPath insert the following code

NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:@"tablecellbackground" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
cell.backgroundView  = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
cell.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cell.backgroundView.frame = cell.bounds;

 

Follow these steps to insert a custom content view into a UITableViewCell.

Step 1. Create a new view with your custom code in a separate .xib file. Let say the viewController's name is TableSlideViewController.

Step 2. Insert the following code into the viewController which has your UITableView

 
- (void)slideTableCellView:(id)sender
{
 UITableViewCell *cell = sender;
 if (slideView == nil)
 {
 slideView = [[TableSlideViewController alloc] initWithNibName:@"TableSlideViewController" bundle:nil];
 }
 slideView.view.frame = CGRectMake(-320, 0, 320, 59);
 [cell.contentView addSubview:slideView.view];
 CGAffineTransform slideIn = CGAffineTransformMakeTranslation(320, 0);
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:0.5];
 slideView.view.transform = slideIn;
 [UIView commitAnimations];
}

Step 3. Now call the method we created in Step 2 from UITableView didSelectRowAtIndexPath delegate method

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 [self slideTableCellView:self];
}

Adding a header to the UITableView Class

 UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
 label.backgroundColor = [UIColor clearColor];
 label.font = [UIFont boldSystemFontOfSize:15];
 label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.8];
 label.textAlignment = UITextAlignmentLeft;
 label.textColor = [UIColor whiteColor];
 label.text = @"Header Text"; 
  myTable.tableHeaderView = label;

Add a footer view to the UITableView Class

UILabel *label3 = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
 label3.backgroundColor = [UIColor clearColor];
 label3.font = [UIFont systemFontOfSize:15];
 label3.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.8];
 label3.textAlignment = UITextAlignmentLeft;
 label3.textColor = [UIColor whiteColor];
 label3.text = @"Footer Text";
 myTable.tableFooterView = label3;

 

To Listen to NSNotificationCenter and creating custom notifications across the iPhone application.

Posting a custom notification with the name "CustomNotificationPost" (at the end of a particular specific function/method)

[[NSNotificationCenter defaultCenter] postNotificationName:@"CustomNotificationPost" object:self];

To listen to the notification if the method has finished and notified to the NSNotificationCenter and call a function "MyFunction", to execute when being notified.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MyFunction) name:@"CustomNotificationPost" object:nil];

 

This is the third iteration of Purplehaze Applications site, since this company started in July 2008. With my application numbers expanding slowly but steadily, the previous iteration of the site couldn't handle my developing needs. I started with Joomla CMS when I had no clue about website management systems like Joomla, I couldn't get my head around its layout, design and management. Most of all, I couldn't get the site to look the way I wanted it to. Since I upgraded my servers, I got rid of Joomla and went back to age old HTML and Javascript.

"Happy New Year!"

Not until recently, that I realized the power of Joomla! Here is the newest edition, very aptly on this new year's day.

Sponsors Ad