Tableview not scrolling smooth with static data - ios

I am using custom cell and headerView with static images and footerView but not scrolling as smoothly as it should scroll, it is getting stuck in middle and then scrolls........
Header
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerview = [[UIView alloc]init];
if (section == 2) {
headerview.frame = CGRectMake(0, 30, tableView.frame.size.width, 117);
Button = [[UIButton alloc]initWithFrame:CGRectMake(0, 18, headerview.frame.size.width, 100)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, tableView.frame.size.width, 17)];
label.text = #"Siddharth and hiren Like this";
label.font = [UIFont systemFontOfSize:10];
label.textColor = [UIColor blackColor];
[headerview addSubview:label];
}
else
{
headerview.frame = CGRectMake(0, 0, tableView.frame.size.width, 100);
Button = [[UIButton alloc]initWithFrame:headerview.frame];
}
// sheap top left and top right
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:headerview.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(7.0, 7.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
headerview.frame = headerview.bounds;
maskLayer.path = maskPath.CGPath;
headerview.layer.mask = maskLayer;
// shape for button bottom
headerview.backgroundColor = [UIColor whiteColor];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 0, headerview.frame.size.width, 1);
bottomBorder.backgroundColor = [UIColor colorWithRed:217/255.0f green:217/255.0f blue:217/255.0f alpha:1].CGColor;
bottomBorder.shadowColor = [[UIColor blackColor] CGColor];
bottomBorder.shadowOpacity = 0.9f;
bottomBorder.shadowRadius = 0.3f;
[headerview.layer addSublayer:bottomBorder];
headerview.layer.shouldRasterize = YES;
// Button Imageview
UIImageView *buttonimg = [[UIImageView alloc]initWithFrame:Button.bounds];
buttonimg.image = [UIImage imageNamed:[_SecImgArray objectAtIndex:section]];
buttonimg.layer.shouldRasterize = YES;
[Button addSubview:buttonimg];
// imageview overlay
UIView *overlay = [[UIView alloc]initWithFrame:Button.bounds];
overlay.alpha = 0.3;
overlay.backgroundColor = [UIColor blackColor];
overlay.layer.shouldRasterize = YES;
[buttonimg addSubview:overlay];
[Button addTarget:self action:#selector(Expand: and:) forControlEvents:UIControlEventTouchUpInside];
Button.tag = section;
if ([[AllNewsdic objectForKey:#"posts"] count] == 0) {
[Button setTitle:[[[DownloadData objectForKey:#"posts"]objectAtIndex:section]objectForKey:#"title"] forState:UIControlStateNormal];
}
else
{
[Button setTitle:[[[AllNewsdic objectForKey:#"posts"]objectAtIndex:section]objectForKey:#"title"] forState:UIControlStateNormal];
}
[Button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
Button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
Button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
Button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
Button.titleLabel.numberOfLines = 0;
Button.titleLabel.font = [UIFont fontWithName:#"Avenir-Black" size:12];
Button.layer.shadowColor = [UIColor greenColor].CGColor;
Button.layer.shadowOpacity = 0.4;
Button.layer.shadowRadius = 1.0f;
Button.layer.cornerRadius = 7;
Button.layer.masksToBounds = YES;
Button.layer.shouldRasterize = YES;
[headerview addSubview:Button];
return headerview;}
Footer
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *fotter = [[UIView alloc]initWithFrame:CGRectMake(0, -10, tableView.frame.size.width, 30)];
fotter.backgroundColor = [UIColor whiteColor];
// corner redius
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:fotter.bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
cornerRadii:CGSizeMake(7.0, 7.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
fotter.frame = fotter.bounds;
maskLayer.path = maskPath.CGPath;
// maskLayer.backgroundColor = [UIColor colorWithRed:217/255.0f green:217/255.0f blue:217/255.0f alpha:1].CGColor;
fotter.layer.mask = maskLayer;
// Bottom layer
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 32, fotter.frame.size.width, 2);
bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
[fotter.layer addSublayer:bottomBorder];
// top Layer
CALayer *topLayer = [CALayer layer];
topLayer.frame = CGRectMake(13, 0, fotter.frame.size.width - 26, 0.7);
topLayer.backgroundColor = [UIColor colorWithRed:197/255.0f green:187/255.0f blue:188/255.0f alpha:1].CGColor;
topLayer.shadowOpacity = 0.6f;
topLayer.shadowRadius = 0.5f;
[fotter.layer addSublayer:topLayer];
// Like bUtton
likebutton = [[UIButton alloc]initWithFrame:CGRectMake(0, -3, fotter.frame.size.width/2, fotter.frame.size.height + 3)];
likebutton.titleLabel.font = [UIFont systemFontOfSize:10];
likebutton.titleLabel.tintColor = [UIColor colorWithRed:197/255.0f green:187/255.0f blue:188/255.0f alpha:1];
[likebutton addTarget:self action:#selector(like:) forControlEvents:UIControlEventTouchUpInside];
[likebutton setTitle:#"1 likes" forState:UIControlStateNormal];
likebutton.tag = section;
like = [[UIImageView alloc]initWithFrame:CGRectMake(40 ,8, 15, 15)];
like.image = [UIImage imageNamed:#"SimpleLike.png"];
[likebutton addSubview:like];
[likebutton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[fotter addSubview:likebutton];
// Follow Button
NSLog(#"%f",fotter.frame.size.width/2 + 1);
follow = [[UIButton alloc]initWithFrame:CGRectMake(fotter.frame.size.width/2 , -3, fotter.frame.size.width/2, fotter.frame.size.height + 3)];
follow.titleLabel.font = [UIFont systemFontOfSize:10];
follow.titleLabel.tintColor = [UIColor colorWithRed:197/255.0f green:187/255.0f blue:188/255.0f alpha:1];
[follow setTitle:#"Follow" forState:UIControlStateNormal];
followimage = [[UIImageView alloc]initWithFrame:CGRectMake(35 ,8, 17, 17)];
followimage.image = [UIImage imageNamed:#"Follow.png"];
[follow addSubview:followimage];
[follow setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
follow.tag = section;
[follow addTarget:self action:#selector(Follow:) forControlEvents:UIControlEventTouchUpInside];
[fotter addSubview:follow];
return fotter;}
Cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
AllNewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"AllNews"];
cell.one.text = [one objectAtIndex:indexPath.section];
cell.two.text = [two objectAtIndex:indexPath.section];
cell.three.text = [three objectAtIndex:indexPath.section];
[cell.three sizeToFit];
return cell;}
how to set tableview scroll smooth and effective
how to set interface properties
tableview data is static

Use reusable UITableViewCell inside function viewForHeaderInSection and inside viewForFooterInSection
Do not create the new UIView and buttons for each function call.

Your table view scrolling is not smooth because the views inside viewForHeaderInSection and viewForFooterInSection methods are allocated multiple times. Why ? Because whenever you scroll up and down, both the methods are called as and when required.
Check whether header view is already allocated. If it is nil, then and then allocate it and return it. Otherwise, just return it. Same way in case of footer view.
Add comment in case of any doubt..

Related

text transparency|color gradient

I am trying to put transparency (or a color gradient) on the title of an UIButton. I don't know how do that. I have tried to simply put a clearColor on the titleColor but we only see the background color.
So i hope that there is someone here who will be an amazing idea for my problem.
My solution
self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.backgroundColor= [UIColor whiteColor];
self.loginButton.frame = CGRectMake(self.signUpButton.left,
0,
self.signUpButton.frame.size.width,
self.signUpButton.frame.size.height);
[self.loginButton.layer setBackgroundColor:[[UIColor blackColor] CGColor]];
self.loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
self.loginButton.layer.borderWidth = 1.0f;
self.loginButton.layer.cornerRadius = 3.0f;
[self.loginButton addTarget:self action:#selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.loginButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.loginButtonLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:16.0f];
self.loginButtonLabel.textColor = [UIColor whiteColor];
self.loginButtonLabel.text = #"Connexion";
[self.loginButtonLabel sizeToFit];
UIColor *topColor = [UIColor blueColor];
UIColor *bottomColor = [UIColor orangeColor];
self.gradientView = [[UIView alloc] initWithFrame:self.loginButtonLabel.frame];
[self.loginButton addSubview:self.gradientView];
[self.loginButton sendSubviewToBack:self.gradientView];
[self.loginButton addSubview:self.loginButtonLabel];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.gradientView.frame;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1, 0.5);
[self.gradientView.layer addSublayer:gradient];
self.gradientView.layer.mask = self.loginButtonLabel.layer;
self.gradientView.layer.masksToBounds = YES;
self.gradientView.center = CGPointMake(self.loginButton.width / 2, self.loginButton.height / 2);
[self.view addSubview:self.loginButton];
But Now i need to put the gradient on the border. Any idea ?
So my solution is to create a custom button with an UILabel. I will use an UIView with a gradient for color the text.
The solution :
self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.backgroundColor= [UIColor whiteColor];
self.loginButton.frame = CGRectMake(self.signUpButton.left,
0,
self.signUpButton.frame.size.width,
self.signUpButton.frame.size.height);
[self.loginButton.layer setBackgroundColor:[[UIColor blackColor] CGColor]];
self.loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
self.loginButton.layer.borderWidth = 1.0f;
self.loginButton.layer.cornerRadius = 3.0f;
[self.loginButton addTarget:self action:#selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.loginButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.loginButtonLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:16.0f];
self.loginButtonLabel.textColor = [UIColor whiteColor];
self.loginButtonLabel.text = #"Connexion";
[self.loginButtonLabel sizeToFit];
UIColor *topColor = [UIColor blueColor];
UIColor *bottomColor = [UIColor orangeColor];
self.gradientView = [[UIView alloc] initWithFrame:self.loginButtonLabel.frame];
[self.loginButton addSubview:self.gradientView];
[self.loginButton sendSubviewToBack:self.gradientView];
[self.loginButton addSubview:self.loginButtonLabel];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.gradientView.frame;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1, 0.5);
[self.gradientView.layer addSublayer:gradient];
self.gradientView.layer.mask = self.loginButtonLabel.layer;
self.gradientView.layer.masksToBounds = YES;
self.gradientView.center = CGPointMake(self.loginButton.width / 2, self.loginButton.height / 2);
[self.view addSubview:self.loginButton];

Why my button in a UItableView didn't respond?

I've a UItableView with multiple section, In Each section, I've a View which contains a button, and in each of these sections one row is located but I've hided that row.
In short, my tableview is a collection of sections which in turns contains buttons on each section, when I click on the button it didn't respond but once I scroll ,my table from bottom to top the buttons are responded. What is the issue here?
Thanks!
Here is the code:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
sheettable.scrollsToTop=YES;
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)];
CGRect rect= CGRectMake(0, 0, 320,40);
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(UIRectCornerAllCorners) cornerRadii:CGSizeMake(5.0, 5.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame =rect;
maskLayer.path = maskPath.CGPath;
headerView.layer.mask = maskLayer;
headerView.backgroundColor=[UIColor greenColor];
UITextField *label1 = [[UITextField alloc] init] ;
label1.delegate=self;
label1.frame = CGRectMake(5, 1, 200, 35);
label1.font = [UIFont boldSystemFontOfSize:16];
label1.text = [[result2 objectAtIndex:section] objectForKey:#"cat_desc"];
UIButton *btn=[[UIButton alloc]init];
btn.frame=CGRectMake(5, 1, 200, 35);
btn.tag=section;
btn.backgroundColor=[UIColor clearColor];
[headerView addSubview:label1];
[btn addTarget:self action:#selector(selectedsections) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:btn];
cameracategory=section;
return headerView;
}
-(void)selectedsections
{
if(cameracategory==0)
{
NSLog(#"At Index");
}
if(cameracategory==1)
{
NSLog(#"At Index");
}
if(cameracategory==2)
{
NSLog(#"At Index");
}
if(cameracategory==3)
{
NSLog(#"At Index");
}
if(cameracategory==4)
{
NSLog(#"At Index");
}
}
I tested your code, it works, but I created the UITableView myself. You should check that. Also try to write more readable code :) it will be more easier in the future :)
You have some misaligned frames (subviews are bigger than parent).
- (void)sectionButtonAction:(UIButton *)sender {
NSLog(#"Section button tapped: %i", sender.tag);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CGRect tableRect = tableView.frame;
CGRect headerRect = CGRectZero;
headerRect.size.width = tableRect.size.width;
headerRect.size.height = 22;
CGRect bezierRect = CGRectZero;
bezierRect.size.width = tableRect.size.width;
bezierRect.size.height = 44;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setFrame:bezierRect];
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bezierRect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(5, 5)].CGPath];
UIView *headerView = [[UIView alloc] initWithFrame:headerRect];
[headerView setBackgroundColor:[UIColor greenColor]];
[[headerView layer] setMask:maskLayer];
CGRect labelRect = CGRectZero;
labelRect.origin.x = 5;
labelRect.origin.y = 1;
labelRect.size.width = 200;
labelRect.size.height = 35;
UILabel *headerLabel = [[UILabel alloc] initWithFrame:labelRect];
[headerLabel setFont:[UIFont boldSystemFontOfSize:16]];
[headerLabel setText:#"asd"];
[headerView addSubview:headerLabel];
CGRect buttonRect = labelRect;
UIButton *headerButton = [UIButton buttonWithType:UIButtonTypeCustom];
[headerButton setFrame:buttonRect];
[headerButton setTag:section];
[headerButton addTarget:self action:#selector(sectionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:headerButton];
return headerView;
}

Custom drawing UICollectionViewCell subViews for performance optimization

In my UICollectionViewCell subclass I have this code to layout the subViews I want:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, 10, 190, 40)];
_titleLabel.font = [UIFont boldFlatFontOfSize:22];
_titleLabel.backgroundColor = [UIColor clearColor];
_fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, 35, 190, 30)];
_fromLabel.font = [UIFont flatFontOfSize:14];
_fromLabel.backgroundColor = [UIColor clearColor];
UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 90, 90)];
containerView.backgroundColor = [[UIColor colorWithPatternImage:[UIImage imageNamed:#"cream_pixels"]] colorWithAlphaComponent:0.8];
[self.contentView addSubview:containerView];
_iconView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
[_iconView setCenter:containerView.center];
_iconView.backgroundColor = [UIColor whiteColor];
_iconView.contentMode = UIViewContentModeScaleAspectFit;
_iconView.image = [UIImage imageNamed:#"envelopeIcon.png"];
_iconView.backgroundColor = [UIColor clearColor];
[containerView addSubview:_iconView];
_dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(97, self.contentView.frame.size.height - 23, self.contentView.frame.size.width-97, 25)];
[_dateLabel setBackgroundColor:[UIColor clearColor]];
[_dateLabel setFont:[UIFont boldFlatFontOfSize:13]];
[_dateLabel setTextColor:[[UIColor wetAsphaltColor] colorWithAlphaComponent:0.6f]];
[_dateLabel setTextAlignment:NSTextAlignmentLeft];
[_dateLabel setLineBreakMode:NSLineBreakByCharWrapping];
[_dateLabel setNumberOfLines:0];
_typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.f, 0.f , 4, self.contentView.frame.size.height)];
_typeLabel.layer.cornerRadius = 0.f;
_typeLabel.backgroundColor = [UIColor belizeHoleColor];
[self.contentView addSubview:_titleLabel];
[self.contentView addSubview:_fromLabel];
[self.contentView addSubview:_typeLabel];
[self.contentView addSubview:_dateLabel];
self.backgroundColor = [[UIColor cloudsColor] colorWithAlphaComponent:1.f];
self.layer.cornerRadius = 3.2f;
self.layer.masksToBounds = NO;
self.layer.contentsScale = [UIScreen mainScreen].scale;
self.layer.borderColor = [[UIColor silverColor] colorWithAlphaComponent:0.2].CGColor;
self.layer.borderWidth = 0.5f;
self.layer.shadowOpacity = 0.35f;
self.layer.shadowRadius = 3.f;
self.layer.shadowOffset = CGSizeMake(0, 3.f);
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
self.layer.shouldRasterize = YES;
[_titleLabel setText:#"Nuevo Mensaje"];
}
return self;
}
I understand that for performance, it's recommended that the subviews are added to the cell using custom drawing, and not by layering the contents of it.
How can I achieve this?

UIView not visible in UITableView Header

Why won't my UIView (created below) show up in the UITableViewHeader that I try to add it to?
UIView *view = [[UIView alloc] initWithFrame: CGRectMake ( 20, 20, 400, 400)];
searchBar = (UISearchBar *)self.tableView.tableHeaderView;
[searchBar.subviews objectAtIndex:0] removeFromSuperview];
searchBar.backgroundColor = [UIColor clearColor];
[view addSubview:searchBar];
self.tableView.tableHeaderView = nil;
view.backgroundColor = [UIColor redColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width, 60)];
label.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:.35];
label.shadowOffset = CGSizeMake(0, -1.0);
label.text = #"188 People";
label.textColor = [UIColor grayColor];
label.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:12.0];
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
self.tableView.tableHeaderView = view;
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame: CGRectMake ( 20, 20, 400, 400)];
searchBar = (UISearchBar *)self.tableView.tableHeaderView;
[searchBar.subviews objectAtIndex:0] removeFromSuperview];
searchBar.backgroundColor = [UIColor clearColor];
[view addSubview:searchBar];
view.backgroundColor = [UIColor redColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width, 60)];
label.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:.35];
label.shadowOffset = CGSizeMake(0, -1.0);
label.text = #"188 People";
label.textColor = [UIColor grayColor];
label.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:12.0];
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
return view;//Please note the header will look the same for each section. You can add a switch or if/else to augment this
}
-As a side note, if you're planning on using the label here to set the text for the header, I suggest looking into the following methods:
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

iOS tableview section header won't stay on top of view

As the title implies, the section header I have in my table, when scrolling won't stay on top. It was working before but for some reason, it stopped. I can't figure out why for the life of me. Any help would be awesome. thanks.
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [xmlParser.calls count] * 2 + 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return headerHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row % 2 == 0)
return 7;
return 65;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 20)];
headerView.backgroundColor = [UIColor colorWithRed:(51/255.0) green:(54/255.0) blue:(57/255.0) alpha:1.0];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 44.0f, self.tableView.bounds.size.width, 1.0f);
bottomBorder.backgroundColor = [UIColor colorWithRed:(130/255.0) green:(130/255.0) blue:(130/255.0) alpha:1.0].CGColor;
[headerView.layer addSublayer:bottomBorder];
CALayer *topBorder = [CALayer layer];
topBorder.frame = CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 1.0f);
topBorder.backgroundColor = [UIColor colorWithRed:(130/255.0) green:(130/255.0) blue:(130/255.0) alpha:1.0].CGColor;
[headerView.layer addSublayer:topBorder];
CALayer *imageBorder = [CALayer layer];
imageBorder.frame = CGRectMake(0.0f, 45, self.tableView.bounds.size.width, 7);
imageBorder.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"texture3.png"]].CGColor;
[headerView.layer addSublayer:imageBorder];
UILabel *countyLabel = [[UILabel alloc] initWithFrame:CGRectMake(136, 0, 75, 20)];
countyLabel.text = #"LEGEND";
countyLabel.backgroundColor = [UIColor clearColor];
countyLabel.font = [UIFont boldSystemFontOfSize:11];
countyLabel.textColor = [UIColor whiteColor];
[headerView addSubview:countyLabel];
UILabel *county = [[UILabel alloc] initWithFrame:CGRectMake(37, 20, 75, 20)];
county.text = #"WA. COUNTY";
county.backgroundColor = [UIColor clearColor];
county.font = [UIFont systemFontOfSize:10];
county.textColor = [UIColor whiteColor];
[headerView addSubview:county];
UIImageView *waCountyImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 20, 18, 18)];
waCountyImage.image = [UIImage imageNamed:#"blue.png"];
[headerView addSubview:waCountyImage];
UILabel *county1 = [[UILabel alloc] initWithFrame:CGRectMake(128, 20, 75, 20)];
county1.text = #"CLA. COUNTY";
county1.backgroundColor = [UIColor clearColor];
county1.font = [UIFont systemFontOfSize:10];
county1.textColor = [UIColor whiteColor];
[headerView addSubview:county1];
UIImageView *caCountyImage = [[UIImageView alloc] initWithFrame:CGRectMake(107, 20, 18, 18)];
caCountyImage.image = [UIImage imageNamed:#"green.png"];
[headerView addSubview:caCountyImage];
UILabel *callType = [[UILabel alloc] initWithFrame:CGRectMake(227, 20, 75, 20)];
callType.text = #"FIRE";
callType.backgroundColor = [UIColor clearColor];
callType.font = [UIFont systemFontOfSize:10];
callType.textColor = [UIColor whiteColor];
[headerView addSubview:callType];
UIImageView *fireImage = [[UIImageView alloc] initWithFrame:CGRectMake(205, 20, 18, 18)];
fireImage.image = [UIImage imageNamed:#"red.png"];
[headerView addSubview:fireImage];
UILabel *callType1 = [[UILabel alloc] initWithFrame:CGRectMake(280, 20, 75, 20)];
callType1.text = #"EMS";
callType1.backgroundColor = [UIColor clearColor];
callType1.font = [UIFont systemFontOfSize:10];
callType1.textColor = [UIColor whiteColor];
[headerView addSubview:callType1];
UIImageView *emsImage = [[UIImageView alloc] initWithFrame:CGRectMake(258, 20, 18, 18)];
emsImage.image = [UIImage imageNamed:#"yellow.png"];
[headerView addSubview:emsImage];
return headerView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier1 = #"cell1";
static NSString *cellidentifier2 = #"cell2";
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"texture3.png"]];
self.tableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"texture3.png"]];
if (indexPath.row % 2 == 0)
{
UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:cellidentifier2];
if (cell2 == nil)
{
cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier2];
[cell2.contentView setAlpha:0];
[cell2 setUserInteractionEnabled:NO];
[cell2 setBackgroundColor:[UIColor clearColor]];
}
return cell2;
}
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:((indexPath.row - 1 ) / 2)];
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier1];
if (cell == nil)
{
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier1];
}
cell.callTypeLabel.text = currentCall.currentCallType;
cell.locationLabel.text = currentCall.location;
cell.unitsLabel.text = currentCall.units;
cell.stationLabel.text = [#"Station: " stringByAppendingString:currentCall.station];
if ([currentCall.county isEqualToString:#"W"]) {
cell.countyImageView.image = [UIImage imageNamed:#"blue.png"];
}
else {
cell.countyImageView.image = [UIImage imageNamed:#"green.png"];
}
if ([currentCall.callType isEqualToString:#"F"]) {
cell.callTypeImageView.image = [UIImage imageNamed:#"red.png"];
}
else {
cell.callTypeImageView.image = [UIImage imageNamed:#"yellow.png"];
}
return cell;
}

Resources