UITableView separator line does not show in iPhone app - ios

I have app in which i am using tableView problem is that when tableView has one record then it does not show separator line but shows when there are two records.
The first cell in tableView is textField. here is the code i am using.
for (UIView *subView in cell.subviews)
{
if (subView.tag == 2 || subView.tag == 22)
{
[subView removeFromSuperview];
}
}
tableView.backgroundView=nil;
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.separatorInset = UIEdgeInsetsZero;
if(indexPath.section==0){
tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,0,248,31)];
tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
tagInputField.textAlignment=UITextAlignmentLeft;
tagInputField.backgroundColor=[UIColor whiteColor];
tagInputField.tag = 2;
tagInputField.delegate = self;
tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;
[tagInputField.layer setCornerRadius:5.0f];
[tagInputField.layer setMasksToBounds:YES];
tagInputField.layer.borderWidth = 0.3;
tagInputField.layer.borderColor = [UIColor darkGrayColor].CGColor;
tagInputField.font=[UIFont fontWithName:#"Myriad-Pro" size:8];
[tagInputField setText:#"Enter tag here "];
tagInputField.textColor =[UIColor grayColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[cell addSubview:tagInputField];
return cell;
}
if(indexPath.section==1) {
UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(228, 8, 18, 18)];
crossButton.tag = 22; //use a tag value that is not used for any other subview
//crossButton.backgroundColor = [UIColor purpleColor];
crossButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Cross.png"]];
[cell addSubview:crossButton];
cell.textLabel.font =[UIFont fontWithName:#"Myriad-Pro" size:8];
cell.textLabel.textColor =[UIColor grayColor];
cell.backgroundColor=[UIColor whiteColor];
cell.textLabel.text =[tagArray objectAtIndex:indexPath.row];
[crossButton addTarget:self action:#selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside];
[tagInputField setFrame:CGRectMake(5,0,248,31)];
tableView.backgroundColor=[UIColor whiteColor];
[tagInputField.layer setCornerRadius:0.0f];
[tagInputField.layer setMasksToBounds:YES];
tagInputField.layer.borderWidth = 0.0;
tagInputField.layer.borderColor = [UIColor clearColor].CGColor;
return cell;
}

When you will have only 1 record then separator will not show, and you should setting the separator for tableView at viewDidLoad look like
- (void)viewDidLoad
{
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
and in any case you want to show your own separator for every single cell ten try to add a imageView or somrthing witch share by the table cell
UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 1024, 1)];
separatorView.layer.borderColor = [UIColor redColor].CGColor;
separatorView.layer.borderWidth = 1.0;
[cell.contentView addSubview:separatorView];
How to customize tableView separator in iPhone
go for more on it....

Just try like this in side the Cell_for_Row_At_Index_path delegate method:
[tableView setSeparatorInset:UIEdgeInsetsZero];
[tableView setSeparatorColor:[UIColor greenColor]];
just paste this line and check.

add an empty footer at the end of the tableview to show the separator. To do so implement the following tableview delegate method in your class with your other tableview delegate functions:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
}

I used this to add last cell separator line....
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// To "clear" the footer view
UIView *separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 1024, 1)];
separatorLine.layer.borderColor = [UIColor grayColor].CGColor;
separatorLine.layer.borderWidth = 1.0;
return separatorLine;
}

I found none of the above answers worked. I was particularly wary of the answer suggesting adding a UIView to look like the line.
In the end I found that this answer worked for me:
tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
In another answer it was suggested that adding worked better
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
but I found that this was unnecessary.
All the credit goes to user859045 and samvermette for their answers on different threads. samvermette's thread especially has a lot of answers on this topic which are very helpful and worth a look.

Related

UITextField placeholder alignment scrolling trouble

I'm working on a registration form actually and i'm facing some kind of trouble.
I'm using an UITextField into my cell and I wrote a string into the placeholder. Everything runs fine until I try to center the UITextField.textAlignment. It, somehow, manages not to center it. I checked it up and did some test and I think it might be an issue du to Constraints (I really want my form to work for the iphone 4s, 5, 6 and 6+ screens). It looks almost centered when i'm on iphone 6 but then you see the string less and less centered, going for right side if you switch to iphone 5 then iphone 4s.. So far I only used both heights Constraints.
Now the "good" thing is when I scroll my tableView, if my cells get out of sight, once I reload my cells, the placeholder string appears a second time but in the right place (the real center this time) with the old missplaced placeholder string. I would like this placeholder showing when I scroll appears when I first load my table because it seems it is the exact result I want to get. But this only appears when I try to center the placeholder, if i don't, there is no second placeholder string showing. I'll give you 2 links for the pictures, since my english is terrible, you guys might be able to understand better this way.
+= Nothing is happening into my code when I scroll the tableView, it is running the same CellForRowAtIndexPath but still with different result.
Thank you for all advices and help you guys will bring to me
Normal screen with Placeholder not totally on center:
Buggy screen with the second Placeholder on right position:
Here is my code running:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = #"id";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
if (indexPath.section == 0){
self.LastName = [[UITextField alloc] initWithFrame:cell.contentView.bounds];
self.LastName.placeholder= #"Last Name";
self.LastName.autocorrectionType = UITextAutocorrectionTypeNo;
self.LastName.textAlignment = NSTextAlignmentCenter;
self.LastName.delegate = self;
[self.LastName setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[self.LastName setTextColor:[UIColor whiteColor]];
[cell.contentView addSubview:self.LastName];
[cell.contentView.layer setBorderColor:[UIColor whiteColor].CGColor];
}
else if (indexPath.section == 1)
{
self.Name = [[UITextField alloc] initWithFrame:cell.contentView.bounds];
self.Name.placeholder= #"Name";
self.Name.autocorrectionType = UITextAutocorrectionTypeNo;
self.Name.textAlignment = NSTextAlignmentCenter;
self.Name.delegate = self;
[self.Name setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[self.Name setTextColor:[UIColor whiteColor]];
[cell.contentView addSubview:self.Name];
[cell.contentView.layer setBorderColor:[UIColor whiteColor].CGColor];
}
else if (indexPath.section == 2)
{
self.Email = [[UITextField alloc] initWithFrame:cell.contentView.bounds];
self.Email.placeholder= #"Email";
self.Email.autocorrectionType = UITextAutocorrectionTypeNo;
self.Email.textAlignment = NSTextAlignmentCenter;
self.Email.delegate = self;
[self.Email setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[self.Email setTextColor:[UIColor whiteColor]];
[cell.contentView addSubview:self.Email];
[cell.contentView.layer setBorderColor:[UIColor whiteColor].CGColor];
}
else if (indexPath.section == 3)
{
self.Password = [[UITextField alloc] initWithFrame:cell.contentView.bounds];
self.Password.placeholder= #"Password";
self.Password.autocorrectionType = UITextAutocorrectionTypeNo;
self.Password.textAlignment = NSTextAlignmentCenter;
self.Password.delegate = self;
[self.Password setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[self.Password setTextColor:[UIColor whiteColor]];
[cell.contentView addSubview:self.Password];
[cell.contentView.layer setBorderColor:[UIColor whiteColor].CGColor];
}
else if (indexPath.section == 4)
{
self.RepetePassword = [[UITextField alloc] initWithFrame:cell.contentView.bounds];
self.RepetePassword.placeholder= #"Repeat password";
self.RepetePassword.autocorrectionType = UITextAutocorrectionTypeNo;
self.RepetePassword.textAlignment = NSTextAlignmentCenter;
self.RepetePassword.delegate = self;
[self.RepetePassword setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[self.RepetePassword setTextColor:[UIColor whiteColor]];
[cell.contentView addSubview:self.RepetePassword];
[cell.contentView.layer setBorderColor:[UIColor whiteColor].CGColor];
}
else if (indexPath.section == 5)
{
cell.textLabel.text = #"Register";
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [UIColor whiteColor];
[cell.contentView.layer setBackgroundColor:[UIColor greenColor].CGColor];
[cell.contentView.layer setBorderColor:[UIColor clearColor].CGColor];
}
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [UIView new];
cell.selectedBackgroundView = [UIView new];
[cell.contentView.layer setBorderWidth:1.0f];
[cell.contentView.layer setCornerRadius:20.0f];
[cell.contentView.layer setMasksToBounds:YES];
return cell;
}
The first thing is that you are allocating your uitextfield in cellForRowAtIndexPath method thats why they appears again and again when you are scrolling.Because nature of uitableview is do whatever developer want in visible cells not in the out of screen thats why when you scrolling this method calling again and again. Just try to allocate textfield in viewDidLoad method or somewhere else.
The second thing is to make them visible as you wanted, you may just use constraints center horizantically and vertically in uitableviewcell. To do that in UI just select your uitextfield hold the control key and drag it in that then click center horizanticall and vertically.
I hope these advices can solve your problems.

UITableview slow scroll and increase ram after some scrolls

this is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"hourCell" forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text=hoursarray[indexPath.row];
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}
UIButton *buttonOff = [UIButton buttonWithType:UIButtonTypeCustom];
buttonOff.layer.cornerRadius = 5.0f;
UIButton *buttonT1 = [UIButton buttonWithType:UIButtonTypeCustom];
buttonT1.layer.cornerRadius = 5.0f;
UIButton *buttonT2 = [UIButton buttonWithType:UIButtonTypeCustom];
buttonT2.layer.cornerRadius = 5.0f;
buttonOff.frame = CGRectMake(130, 5, 40, 34);
[buttonOff setTitle:#"OFF" forState:UIControlStateNormal];
[buttonOff addTarget:self action:#selector(onButtonOFFTap:) forControlEvents:UIControlEventTouchUpInside];
buttonT1.frame = CGRectMake(190, 5, 40, 34);
[buttonT1 setTitle:#"T1" forState:UIControlStateNormal];
[buttonT1 addTarget:self action:#selector(onButtonT1Tap:) forControlEvents:UIControlEventTouchUpInside];
buttonT2.frame = CGRectMake(250, 5, 40, 34);
[buttonT2 setTitle:#"T2" forState:UIControlStateNormal];
[buttonT2 addTarget:self action:#selector(onButtonT2Tap:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:buttonOff];
[cell.contentView bringSubviewToFront:buttonOff];
buttonOff.tag=indexPath.row;
[cell addSubview:buttonT1];
[cell.contentView bringSubviewToFront:buttonT1];
buttonT1.tag=indexPath.row;
[cell.contentView bringSubviewToFront:buttonT2];
[cell addSubview:buttonT2];
buttonT2.tag=indexPath.row;
if([[NSString stringWithFormat:#"%#",[datiProgrTemp objectAtIndex:indexPath.row+48*day]] isEqual:#"1"])
{
buttonOff.backgroundColor = [UIColor greenColor];
buttonT1.backgroundColor = [UIColor lightGrayColor];
buttonT2.backgroundColor = [UIColor lightGrayColor];
}
if([[NSString stringWithFormat:#"%#",[datiProgrTemp objectAtIndex:indexPath.row+48*day]] isEqual:#"2"])
{
buttonOff.backgroundColor = [UIColor lightGrayColor];
buttonT1.backgroundColor = [UIColor greenColor];
buttonT2.backgroundColor = [UIColor lightGrayColor];
}
if([[NSString stringWithFormat:#"%#",[datiProgrTemp objectAtIndex:indexPath.row+48*day]] isEqual:#"3"])
{
buttonOff.backgroundColor = [UIColor lightGrayColor];
buttonT1.backgroundColor = [UIColor lightGrayColor];
buttonT2.backgroundColor = [UIColor greenColor];
}
return cell;
}
The fact is that after two or three scrolls (fast and smooth) the scrolling goes slow and crappy and the ram used increase.
I tried to put if(cell==nill) but I'm using storyboard and the cell is never nill
Am I wrong in something?
Thanks a lot,
N.
There are a couple problems here.
The whole point of using dequeueReusableCellWithIdentifier: is to reuse your cells and their content. But I see you've used this line:
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}
to remove the cell content at every call to cellForRowAtIndexPath:. This is a waste of using dequeueReusableCellWithIdentifier:.
Nevertheless, your logic is almost correct. You can remove the subviews and create new subviews without having the incremental memory issues you're describing. The problem is you've made a small error:
You're adding the UIButtons directly to the cell's view, for example
[cell addSubview:buttonOff];
but removing the subviews of the cell's content view:
[cell.contentView subviews]
(You're also using bringSubviewToFront: ineffectively for this same reason.)
Because of this mistake, you're not actually removing the buttons at every call to cellForRowAtIndexPath: as you've intended so as you scroll back and forth, buttons are being added one on top of another on top of another, thus increasing memory usage.
To fix this problem, whether you add and remove from cell or cell.contentView, you have to be consistent.
All that aside though, since the content of your cells is very similar, I highly recommend you use dequeueReusableCellWithIdentifier: in the way it was intended by actually reusing your cells' content.
Thanks to all. This is the code working good. I added a TableViewCell class that contains only the outlet to the buttons (added buttons graphically in the storyboard):
#import <UIKit/UIKit.h>
#interface CHRTableViewCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UIButton *buttonOFF;
#property (weak, nonatomic) IBOutlet UIButton *buttonT1;
#property (weak, nonatomic) IBOutlet UIButton *buttonT2;
#end
then instantiated cell on tableview controller and pointing to the outlet changed the button's aspect:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CHRTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"hourCell" forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text=hoursarray[indexPath.row];
cell.buttonOFF.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell.buttonOFF.layer.borderWidth = 0.5f;
cell.buttonOFF.layer.cornerRadius = 5.0f;
cell.buttonT1.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell.buttonT1.layer.borderWidth = 0.5f;
cell.buttonT1.layer.cornerRadius = 5.0f;
cell.buttonT2.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell.buttonT2.layer.borderWidth = 0.5f;
cell.buttonT2.layer.cornerRadius = 5.0f;
[cell.buttonOFF setTitle:#"OFF" forState:UIControlStateNormal];
[cell.buttonOFF addTarget:self action:#selector(onButtonOFFTap:) forControlEvents:UIControlEventTouchUpInside];
[cell.buttonT1 setTitle:#"T1" forState:UIControlStateNormal];
[cell.buttonT1 addTarget:self action:#selector(onButtonT1Tap:) forControlEvents:UIControlEventTouchUpInside];
[cell.buttonT2 setTitle:#"T2" forState:UIControlStateNormal];
[cell.buttonT2 addTarget:self action:#selector(onButtonT2Tap:) forControlEvents:UIControlEventTouchUpInside];
cell.buttonOFF.tag=indexPath.row;
cell.buttonT1.tag=indexPath.row;
cell.buttonT2.tag=indexPath.row;
if([[NSString stringWithFormat:#"%#",[datiProgrTemp objectAtIndex:indexPath.row+48*day]] isEqual:#"1"])
{
cell.buttonOFF.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green:200.0f/255.0f blue:60.0f/255.0f alpha:1.0f];
cell.buttonT1.backgroundColor = [UIColor whiteColor];
cell.buttonT2.backgroundColor = [UIColor whiteColor];
}
if([[NSString stringWithFormat:#"%#",[datiProgrTemp objectAtIndex:indexPath.row+48*day]] isEqual:#"2"])
{
cell.buttonOFF.backgroundColor = [UIColor whiteColor];
cell.buttonT1.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green:200.0f/255.0f blue:60.0f/255.0f alpha:1.0f];;
cell.buttonT2.backgroundColor = [UIColor whiteColor];
}
if([[NSString stringWithFormat:#"%#",[datiProgrTemp objectAtIndex:indexPath.row+48*day]] isEqual:#"3"])
{
cell.buttonOFF.backgroundColor = [UIColor whiteColor];
cell.buttonT1.backgroundColor = [UIColor whiteColor];
cell.buttonT2.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green:200.0f/255.0f blue:60.0f/255.0f alpha:1.0f];;
}
return cell;
}

UITableview Cell Height is not calculated properly and cells overlap

I need to create and populate custom cells. These cells height are huge about 300-400.
So I have a populateCellView function , I call that function on heightForRowAtIndexPath to calculate height and in cellForRowAtIndexPath to add that view to cell content view, but somehow sometimes cells overlap.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self populateCellView:indexPath.row].frame.size.height;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *populateCell= nil;
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
populateCell=[[UIView alloc] initWithFrame:CGRectZero];
[[populateCell layer] setBorderWidth:2.0f];
populateCell= [self populateCellView:indexPath.row];
[[cell contentView] addSubview:populateCell];
}
if (!populateCell){
populateCell = (UIView*)[cell viewWithTag:1];
populateCell= [self populateCellView:indexPath.row];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
populate view function:
-(UIView *)populateCellView:(int)forCase
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width,500)];
[view setBackgroundColor:[UIColor colorWithRed:40/255.0 green:150/255.0 blue:213/255.0 alpha:1.0]];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
if ([view subviews]){
for (UIView *subview in [view subviews]) {
[subview removeFromSuperview];
}
}
UILabel *caseNumberLabel;
UILabel *caseNameLabel;
UILabel *caseSummaryLabel;
UILabel *caseAncLabel;
UILabel *caseNumberText;
UILabel *caseNameText;
UILabel *caseSummaryText;
UILabel *caseAncText;
//static label for case number
caseNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,10,250, 50)];
caseNumberLabel.textColor = [UIColor whiteColor];
caseNumberLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:24.0f];
caseNumberLabel.text =#"Case Number:";
caseNumberLabel.backgroundColor = [UIColor clearColor];
caseNumberLabel.numberOfLines=0;
caseNumberLabel.adjustsFontSizeToFitWidth = NO;
caseNumberLabel.tag=forCase;
caseNumberLabel.frame=[self calculateLabelFrame:caseNumberLabel];
//case number from plist
caseNumberText = [[UILabel alloc] initWithFrame:CGRectMake(caseNumberLabel.frame.size.width+50,caseNumberLabel.frame.origin.y,self.view.frame.size.width-caseNumberLabel.frame.size.width-50, 50)];
caseNumberText.textColor = [UIColor whiteColor];
caseNumberText.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:24.0f];
caseNumberText.text =[[self agenda] getCaseNumber:forCase];
caseNumberText.backgroundColor = [UIColor clearColor];
caseNumberText.numberOfLines=0;
caseNumberText.adjustsFontSizeToFitWidth = NO;
caseNumberText.tag=forCase;
//[caseNumberLabel sizeToFit];
caseNumberText.frame=[self calculateLabelFrame:caseNumberText];
//static label for case name
caseNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,caseNumberText.frame.origin.y + caseNumberText.bounds.size.height+5,250, 50)];
caseNameLabel.textColor =[UIColor whiteColor];
caseNameLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:24.0f];
caseNameLabel.text =#"Case Name:";
caseNameLabel.backgroundColor = [UIColor clearColor];
caseNameLabel.numberOfLines=0;
caseNameLabel.adjustsFontSizeToFitWidth = NO;
caseNameLabel.tag=forCase;
//[caseNumberLabel sizeToFit];
caseNameLabel.frame=[self calculateLabelFrame:caseNameLabel];
//case name from plist
caseNameText = [[UILabel alloc] initWithFrame:CGRectMake(caseNameLabel.frame.size.width+50,caseNameLabel.frame.origin.y,self.view.frame.size.width-caseNameLabel.frame.size.width-50, 50)];
caseNameText.textColor = [UIColor whiteColor];
caseNameText.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:24.0f];
caseNameText.text =[[self agenda] getCaseName:forCase];
caseNameText.backgroundColor = [UIColor clearColor];
caseNameText.numberOfLines=0;
//caseNameText.adjustsFontSizeToFitWidth = NO;
caseNameText.tag=forCase;
[caseNameText sizeToFit];
//caseNameText.lineBreakMode = NSLineBreakByWordWrapping;
caseNameText.frame=[self calCellLabelFrame:caseNameText previousLabel:caseNameLabel];
//static label for case summary
caseSummaryLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,caseNameText.frame.origin.y + caseNameText.bounds.size.height+20,250, 50)];
caseSummaryLabel.textColor = [UIColor whiteColor];
caseSummaryLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:24.0f];
caseSummaryLabel.text =#"Case Summary:";
caseSummaryLabel.backgroundColor = [UIColor clearColor];
caseSummaryLabel.numberOfLines=0;
caseSummaryLabel.adjustsFontSizeToFitWidth = NO;
caseSummaryLabel.tag=forCase;
//[caseSummaryLabel sizeToFit];
caseSummaryLabel.frame=[self calculateLabelFrame:caseSummaryLabel];
//case name from plist
caseSummaryText = [[UILabel alloc] initWithFrame:CGRectMake(caseSummaryLabel.frame.size.width+50,caseSummaryLabel.frame.origin.y,self.view.frame.size.width-caseSummaryLabel.frame.size.width-100, 50)];
caseSummaryText.textColor = [UIColor whiteColor];
caseSummaryText.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:24.0f];
caseSummaryText.text =[[self agenda] getCaseSummary:forCase];
caseSummaryText.backgroundColor = [UIColor clearColor];
caseSummaryText.numberOfLines=0;
//caseSummaryText.adjustsFontSizeToFitWidth = NO;
caseSummaryText.tag=forCase;
[caseSummaryText sizeToFit];
//caseSummaryText.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
caseSummaryText.frame=[self calCellLabelFrame:caseSummaryText previousLabel:caseSummaryLabel];
//static label for anc
caseAncLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,caseSummaryText.frame.origin.y + caseSummaryText.bounds.size.height+15,250, 50)];
caseAncLabel.textColor = [UIColor whiteColor];
caseAncLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:24.0f];
caseAncLabel.text =#"ANC:";
caseAncLabel.backgroundColor = [UIColor clearColor];
caseAncLabel.numberOfLines=0;
caseAncLabel.adjustsFontSizeToFitWidth = NO;
caseAncLabel.tag=forCase;
//[ccaseAncLabel sizeToFit];
caseAncLabel.frame=[self calculateLabelFrame:caseAncLabel];
//case name from plist
caseAncText = [[UILabel alloc] initWithFrame:CGRectMake(caseAncLabel.frame.size.width+50,caseAncLabel.frame.origin.y,self.view.frame.size.width-caseAncLabel.frame.size.width-50, 50)];
caseAncText.textColor = [UIColor whiteColor];
caseAncText.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:24.0f];
caseAncText.text =[[self agenda] getCaseAnc:forCase];
caseAncText.backgroundColor = [UIColor clearColor];
caseAncText.numberOfLines=0;
//caseAncText.adjustsFontSizeToFitWidth = NO;
caseAncText.tag=forCase;
[caseAncText sizeToFit];
//caseSummaryText.lineBreakMode = NSLineBreakByWordWrapping;
caseAncText.frame=[self calCellLabelFrame:caseAncText previousLabel:caseAncLabel];
//add button
UIButton *acceptButton=[UIButton buttonWithType:UIButtonTypeCustom];
[acceptButton setTag:forCase];
acceptButton.titleLabel.tag=1;
[acceptButton setFrame:CGRectMake(caseAncLabel.frame.size.width+50,caseAncText.frame.origin.y + caseAncText.bounds.size.height+20,181,39)];
NSString *radioButtonImage=#"view_attachment.png";
UIImage *acceptbuttonImage = [UIImage imageNamed:radioButtonImage];
[acceptButton setBackgroundImage:acceptbuttonImage forState:UIControlStateNormal];
[acceptButton addTarget:self action:#selector(showAttachements:) forControlEvents:UIControlEventTouchUpInside];
//whie line
UIView *anotherline = [[UIView alloc] initWithFrame:CGRectMake(0, acceptButton.frame.origin.y + acceptButton.bounds.size.height+15, self.view.frame.size.width, 1)];
anotherline.backgroundColor=[UIColor whiteColor];
anotherline.tag=forCase;
[view addSubview:acceptButton];
[view addSubview: caseNumberLabel];
[view addSubview:caseNumberText];
[view addSubview:caseNameLabel];
[view addSubview:caseNameText];
[view addSubview:caseSummaryLabel];
[view addSubview:caseSummaryText];
[view addSubview:caseAncText];
[view addSubview:caseAncLabel];
[view addSubview:anotherline];
view.frame = CGRectMake(0,0, self.view.frame.size.width,anotherline.frame.origin.y + anotherline.bounds.size.height+5);
CGFloat redLevel = rand() / (float) RAND_MAX;
CGFloat greenLevel = rand() / (float) RAND_MAX;
CGFloat blueLevel = rand() / (float) RAND_MAX;
view.backgroundColor = [UIColor colorWithRed: redLevel
green: greenLevel
blue: blueLevel
alpha: 1.0];
return view;
}
I call reload data like this
dispatch_async(dispatch_get_main_queue(), ^{
[_agenda loadFromPlist];
[[self tableView] reloadData];
});
Any idea why cells overlaps?
Its your UITableview cellforIndexPath causing overlap
try this
if (!populateCell){
populateCell = (UIView*)[cell viewWithTag:1];
populateCell= [self populateCellView:indexPath.row];
if ([[cell contentView] subviews]){
for (UIView *subview in [[cell contentView] subviews]) {
[subview removeFromSuperview];
}
}
[[cell contentView] addSubview:populateCell];
}
cell.backgroundColor=[UIColor clearColor];
At the end of the UITableViewDataSource method, tableView:cellForRowAtIndexPath:, you have to call [[cell contentView] addSubView:populateCell]. If the table dequeued a cell successfully, you have to retrieve the appropriate populateCell and add it to the contentView.
If you use storyboards, and set a different height for the cells, and the rows in the tableview, the height will usually overlap. The other answers are also highly valid, but usually when I've encountered this problem, the bug lies in a different value on row height and cell height in the tableview object in your storyboard...

Is there a way to change the font color of all instances of UITableview's header

The new iOS 7 has changed the default font color of the section headers in tableview. The problem is that my background image makes the text hard to read. I know I could change my background but I would like to change the color of all the textviews. I have changed the uinavigationbar color in my apps delegate before. I would like to use something like that for tableview if possible. I have read this method:
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}else{
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 8, 320, 16);
label.textColor = [UIColor whiteColor];
label.text = sectionTitle;
UIView *view = [[UIView alloc] init];
[view addSubview:label];
return view;
}
My problem with this is that I would have to implement it on a per tableviewcontroller basis. Also when using this I'm not sure how to prevent the text from going off the page and being unreadable.
Any suggestions would be great. Thanks in advance.
EDIT: I have decided to add a little clarification just for show using some suggested code here remains my problem with this solution.
EDIT: To accompany answer. I found that this is also needed to create the space for multiple lines for header.
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == ?) {
return 60;
}
else{
return 44;
}
}
You must use following method to change your headerview :
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,yourWidth,YourHeight)] ;
headerView.backgroundColor = [UIColor colorWithRed:0.5058f green:0.6118f blue:0.8078f alpha:1.0f];
tableView.sectionHeaderHeight = headerView.frame.size.height;
tableView.tableHeaderView.clipsToBounds = YES;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 13,320, 22)] ;
label.text = [self tableView:tableView titleForHeaderInSection:section];
label.font = [UIFont boldSystemFontOfSize:16.0];
label.shadowOffset = CGSizeMake(0, 1);
label.shadowColor = [UIColor grayColor];
label.backgroundColor = [UIColor clearColor];
// Chnage your title color here
label.textColor = [UIColor whiteColor];
[label sizeToFit];
label.numberOfLines = 2 ;
[headerView addSubview:label];
return headerView;
}

iOS switching between UIWebViews causing memory warning

Hi i have created a custom tab bar that hides and shows certain web views depending on which tab your on i'm currently loading all three web views on an operation queue then making them visable and invisable depending on the selected tab. problem is its so slow to load and scroll and i'm getting a recieved memory warning
heres what i have done so far
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *subviews = [cell subviews];
for(UIView *subview in subviews) if([subview tag] == 4) [subview removeFromSuperview];
UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)];
UIView *sendingMessage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
UIActivityIndicatorView *sendingSpinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(25, 15, 50, 50)];
UILabel *sendingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 65, 100, 20)];
int sendingViewLeft = (loadingView.frame.size.width/2) - (sendingMessage.frame.size.width/2);
int sendingViewTop = 160 - (sendingMessage.frame.size.height/2);
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
sendingMessage.frame = CGRectMake(sendingViewLeft, sendingViewTop, sendingMessage.frame.size.width, sendingMessage.frame.size.height);
sendingMessage.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
sendingMessage.layer.cornerRadius = 10;
sendingSpinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
sendingLabel.textColor = [UIColor whiteColor];
sendingLabel.backgroundColor = [UIColor clearColor];
sendingLabel.text = #"Loading...";
sendingLabel.textAlignment = UITextAlignmentCenter;
sendingLabel.font = [UIFont boldSystemFontOfSize:12];
sendingLabel.shadowColor = [UIColor blackColor];
sendingLabel.shadowOffset = CGSizeMake(0, -1);
[sendingSpinner startAnimating];
[sendingMessage addSubview:sendingLabel];
[sendingMessage addSubview:sendingSpinner];
[loadingView addSubview:sendingMessage];
[loadingView setTag:4];
cell.textLabel.text = #"";
if([self.webViewStatus isEqualToString:#"FALSE"]){
[cell addSubview:loadingView];
self.tableView.userInteractionEnabled = NO;
} else {
[cell addSubview:self.fixturesWebView];
[cell addSubview:self.resultsWebView];
[cell addSubview:self.tablesWebView];
self.tableView.userInteractionEnabled = YES;
}
if(self.selectedTabNumber == 1){
self.fixturesWebView.alpha = 1;
self.resultsWebView.alpha = 0;
self.tablesWebView.alpha = 0;
}
if(self.selectedTabNumber == 2){
self.fixturesWebView.alpha = 0;
self.resultsWebView.alpha = 1;
self.tablesWebView.alpha = 0;
}
if(self.selectedTabNumber == 3){
self.fixturesWebView.alpha = 0;
self.resultsWebView.alpha = 0;
self.tablesWebView.alpha = 1;
}
return cell;
}
First off, you should consider creating a custom cell rather than creating it at the tableview datasource. Second, when you are getting the webview content, consider using Asynchronous calls to avoid lock ups. This could be done in a block too. If you write delegate methods on the custom cell, you can let the tableview know when things are loaded or not etc.
But it looks like you are making it do too much work when the tableview needs to draw a cell.

Resources