how to remove the line below the tableView cell in iphone - ios

I have iphone app in which i am adding tableView and inside tableView cell i am adding the textfield but problem is that it shows line below the textfiled in tableView as shown in the image attached here is the my code.
I want to remove the line which is coming below the input filed Enter Tag Here
-(UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
// cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"tabelsales.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
//cell.backgroundColor = [UIColor clearColor];
}
for (UIView *subView in cell.subviews)
{
if (subView.tag == 2 || subView.tag == 22)
{
[subView removeFromSuperview];
}
}
tableView.backgroundView=nil;
if(indexPath.section==0){
tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,1,249,28)];
tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
tagInputField.textAlignment=UITextAlignmentLeft;
tagInputField.backgroundColor=[UIColor whiteColor];
tagInputField.tag = 2;
tagInputField.delegate = self;
tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;
tagInputField.font=[UIFont fontWithName:#"Myriad-Pro" size:8];
[tagInputField setText:#"Enter tag here "];
tagInputField.textColor =[UIColor grayColor];
[cell addSubview:tagInputField];
if(tagArray.count >0)
{
[tagInputField setBorderStyle:UITextBorderStyleNone];
}
else {
[tagInputField setBorderStyle:UITextBorderStyleRoundedRect];
}
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(8,1,240,30)];
tableView.backgroundColor=[UIColor whiteColor];
[publishButton setFrame:CGRectMake(40,560,250, 50)];
[descriptionTextImageView setFrame:CGRectMake(48,450,250,90)];
return cell;
}

Update:
1) set property of tableview separatorStyle as UITableViewCellSeparatorStyleNone.
2) set property of SeparatorColor like:
[self.tableView setSeparatorColor:[UIColor clearColor]];
3) other simple way to remove seprator is add custom seprator to simple UIView of 1px height:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor clearColor]; // as per your requirement set color.
[cell.contentView addSubview:separatorLineView];
4) write this delegate method of tableview:
- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;// here remove your footer
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// To "clear" the footer view
return [[UIView new] autorelease];
}
5) try this one:
self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,460) style:UITableViewStylePlain];
self.tblView.delegate=self;
self.tblView.dataSource=self;
[self.view addSubview:self.tblView];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
v.backgroundColor = [UIColor clearColor];
[self.tblView setTableHeaderView:v];
[self.tblView setTableFooterView:v];
[v release];

It can be from xib. Set separator to None, as below screen shot show. Hope it will help. Thanks

You should set separatorStyle property of UITableView to UITableViewCellSeparatorStyleNone.

Related

UITableView not displaying correctly on iPad

On the iPhone, the tableview looks fine, but in the iPad (simulator ios10), this is how it's shown:
Check image here: http://welove.pt/img/ipadtrouble.png
Any idea why its displaying differently on iPhone/iPad?
Also, what's with that white corner by the search icon? why isn't it black?
ViewDidLoad:
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorColor = [UIColor colorWithRed:58/255.0 green:58/255.0 blue:58/255.0 alpha:1.0];
_tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[self.view addSubview:_tableView];
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:(54/255.0) green:(54/255.0) blue:(54/255.0) alpha:1];
cell.selectedBackgroundView = selectionColor;
cell.backgroundColor = [UIColor colorWithRed:(28/255.0) green:(28/255.0) blue:(28/255.0) alpha:1];
cell.textLabel.textColor = [UIColor whiteColor];
}
if (indexPath.section == 0) {
cell.imageView.image = [[UIImage imageNamed:#"defineLocation.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UILabel *ttitle = [[UILabel alloc] initWithFrame:CGRectMake(46, 12, 320, 20)];
ttitle.font = [UIFont systemFontOfSize:17];
ttitle.textColor = [UIColor colorWithRed:(115/255.0) green:(229/255.0) blue:(69/255.0) alpha:1.0];
[ttitle setText:NSLocalizedString(#"current_location", nil)];
[cell.contentView addSubview:ttitle];
} else {
cell.textLabel.text = [[_recentSearchData objectAtIndex:indexPath.row] objectForKey:#"recentTitle"];
}
return cell;
}
Thank you for your help.
Subclassing the UITableViewCell solved the alignment issues.
Regarding that white arrow when the view is popping over on the iPad, i managed to change it's color with:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.popoverPresentationController.backgroundColor = [UIColor colorWithRed:(23/255.0) green:(23/255.0) blue:(23/255.0) alpha:1.0];
}
this viewWillAppear belongs to the UITableViewController that is shown in the popover.
Thanks for your suggestions

TableViewCell is piled up and appear again and again

I implemented TableView with ADLively TableView.
But if I scroll tableView, the cell's texts become to be piled up again and again....
Using "cell.textLabel" is good, adding UILabel is not good than that but if I use "cell.textLabel", I can't resize width of textLabel.
(I want to add UIImageView on the left and right side of text)
So now, I use the way to add UILabel.
What should I do?
Here is the code.
- (void)viewDidLoad {
CGRect rect = CGRectMake(0, 50, 320, self.view.frame.size.height-150);
self.tableView = [[ADLivelyTableView alloc]initWithFrame:rect style:UITableViewStylePlain];
self.tableView = (ADLivelyTableView *)self.tableView;
self.tableView.initialCellTransformBlock = ADLivelyTransformFan;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview: self.tableView];
//self.tableView.backgroundColor = [UIColor blueColor];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.section count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
[self updateCell:cell atIndexPath:indexPath];
if (cell == nil){
myCellView = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"Cell"];
NSMutableArray *set = [self.section objectAtIndex:indexPath.row];
tableTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 220, 30)];
tableTitleLabel.text = [set objectAtIndex:0];
[tableTitleLabel setNumberOfLines:0];
tableTitleLabel.backgroundColor = [UIColor clearColor];
tableTitleLabel.textColor = [UIColor blackColor];
tableTitleLabel.font = [UIFont fontWithName:#"HiraKakuProN-W3" size:15];
tableTitleLabel.adjustsFontSizeToFitWidth = YES;
tableTitleLabel.minimumScaleFactor = 10.0f;
[myCellView.contentView addSubview:tableTitleLabel];
}
NSMutableArray *set = [self.section objectAtIndex:indexPath.row];
[(UILabel *)[cell.contentView viewWithTag:1] setText:[set objectAtIndex:0]];
return cell;
}
- (void)updateCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *set = [self.section objectAtIndex:indexPath.row];
tableTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 220, 30)];
tableTitleLabel.text = [set objectAtIndex:0];
[tableTitleLabel setNumberOfLines:0];
tableTitleLabel.backgroundColor = [UIColor clearColor];
tableTitleLabel.textColor = [UIColor blackColor];
tableTitleLabel.font = [UIFont fontWithName:#"HiraKakuProN-W3" size:15];
tableTitleLabel.adjustsFontSizeToFitWidth = YES;
tableTitleLabel.minimumScaleFactor = 10.0f;
[cell.contentView addSubview:tableTitleLabel];
}
It is not a good idea to keep adding subviews in cell on scroll but if you do not want to change the code that you have already written, use the following to remove all subviews of that cell before you call you updateCell method.
for (UIView *view in [cell subviews])
{
[view removeFromSuperview];
}

UITableview overwriting on olddata

hi im creating chat example and if user add send button adding new object in my arrray and reload data but its overwrite old table.
its my array :
arr1 = [[NSMutableArray alloc] initWithObjects:#"Whats up today ? ", #"Hello.", nil];
Here my source :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simleTableIdentifier = #"TeamCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"TeamCell"];
}
cell.backgroundColor = [UIColor clearColor];
tableView.scrollEnabled = YES;
UIImageView *myRect = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 10, 12)];
myRect.image = [UIImage imageNamed:#"tri.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"jj.jpg"]];
UILabel *label = [[UILabel alloc] init];
label.text = [arr1 objectAtIndex:indexPath.row];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.font =[UIFont systemFontOfSize:14.0];
label.text = [arr1 objectAtIndex: indexPath.row];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.frame = CGRectMake(40, 40, 210, 80);
[label sizeToFit];
UIImageView *imgim = [[UIImageView alloc] initWithFrame:CGRectMake(30, 10, label.frame.size.width+20, label.frame.size.height+20)];
imgim.image = [UIImage imageNamed:#"bg.png"];
CGRect myRectANGLE = CGRectMake(imgim.frame.origin.x+10,imgim.frame.origin.y+10, label.frame.size.width, label.frame.size.height);
[label setFrame:myRectANGLE];
CALayer *addRadius = [imgim layer];
[addRadius setMasksToBounds:YES];
[addRadius setCornerRadius:5.0];
[self.MyTableView setSeparatorColor:[UIColor clearColor]];
[self.MyTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
self.MyTableView.transform = CGAffineTransformMakeScale(1, -1); //in viewDidLoad
cell.transform = CGAffineTransformMakeScale(1, -1);//in tableView:cellForRowAtIndexPath:
[[cell contentView] addSubview:myRect];
[[cell contentView] addSubview:imgim];
[[cell contentView] addSubview:label];
return cell;
}
İf click send button i reload data but its overwite on old-data look like my photo :
-(IBAction)btnTap:(UIButton *)sender {
[arr1 insertObject:Textify.text atIndex:0];
NSLog(#"%i", arr1.count);
[MyTableView reloadData];
}
Try clearing the cell's contentView subview, and then add the new subviews.
Here's a block of code for removing the subviews, taken from this post.
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}
UITableViewCell will be reused while reload, you should not create subviews again to add on cell.contentView.Try to use code below
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"TeamCell"];
UILabel *label = [[UILabel alloc] initWithFrame:someFrame];
label.tag = 1000;
[cell.contentView addSubview:label];
}
UILabel *label = [cell.contentView viewWithTag:1000];
label.text = #"something";

How to Add footer text only in text last section of the tableview?

I want to display footer text only at last section of the TableView.In TableView I have a lot of TableView section it come from API.But I need to display footer message only at bottom of the tableView section how to do it?
(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)];
footer.backgroundColor = [UIColor clearColor];
UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame];
lbl.backgroundColor = [UIColor clearColor];
lbl.text = #"Your Text";
lbl.textAlignment = NSTextAlignmentCenter;
[footer addSubview:lbl];
return footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 10.0;
}
Currently Im used this code.This shows in all section bottom.I need to display only at bottom of the last tableview section.
try this
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 55)];
if (section == array.count -1){
footer.backgroundColor=[UIColor clearColor];
lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,540,40)];
lbl.backgroundColor = [UIColor clearColor];
lbl.text = #" Please add your message";
lbl.textAlignment = NSTextAlignmentCenter;
[lbl setNumberOfLines:10];//set line if you need
[lbl setFont:[UIFont fontWithName:#"HelveticaNeue-Light" size:14.0]];//font size and style
[lbl setTextColor:[UIColor blackColor]];
[footer addSubview:lbl];
self.jobsTableView.tableFooterView=footer;
}
return footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == [tableView numberOfSections] - 1) {
return 60.0;
} else {
return 0.0;
}
}
use
if (section == yourArray.count -1)
{
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)];
footer.backgroundColor = [UIColor clearColor];
UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame];
lbl.backgroundColor = [UIColor clearColor];
lbl.text = #"Your Text";
lbl.textAlignment = NSTextAlignmentCenter;
[footer addSubview:lbl];
}
return footer;
Try this,
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == [tableView numberOfSections] - 1) {
return 10.0;
} else {
return 0.0;
}
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if (section == [tableView numberOfSections] - 1) {
UIView *footer = ..
....
return footer;
} else {
return nil;
}
}
or you can set view as footer to tableview
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)];
....
[self.tableView setTableFooterView:footer];
Please try to use like this if you wanna footerview of tableview.
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)];
footer.backgroundColor = [UIColor clearColor];
UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame];
lbl.backgroundColor = [UIColor clearColor];
lbl.text = #"Your Text";
lbl.textAlignment = NSTextAlignmentCenter;
[footer addSubview:lbl];
footer.backgroundColor = [UIColor blackColor];
self.tableView.tableFooterView = footer;

Add tableview cell with the value of UITextfield

I have a UITextField in a UITableView header. When the user enters anything in the UITextFields, the entry gets added to a NSMutableArray.
I want to create a new UITableCell with the value of the UITextField entry whenever textFieldShouldReturn is called.
I tried using reloadData but that seems to empty my array completely.
Any suggestions? Thanks
- (BOOL)textFieldShouldReturn:(UITextField *)task
{
[task resignFirstResponder];
[self.tasksArray addObject:task.text];
NSLog(#"Test %#", self.tasksArray);
}
My cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
SwipeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[SwipeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
[cell setDelegate:self];
[cell.contentView setBackgroundColor:[UIColor whiteColor]];
// Setting the default inactive state color to the tableView background color
[cell setDefaultColor:self.tableView.backgroundView.backgroundColor];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
[cell.textLabel setText:self.task.text];
self.view = tableView;
cell.mode = SwipeTableViewCellModeExit;
return cell;
}
My UITableView header :
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section{
float width = tableView.bounds.size.width;
int fontSize = 18;
int padding = 1;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0,width, fontSize+11)];
view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
view.userInteractionEnabled = YES;
view.tag = section;
UITextField *task = [[UITextField alloc] initWithFrame:CGRectMake(padding, 2,
width - padding , fontSize + 11)];
task.text = #"Type here";
task.borderStyle = UITextBorderStyleRoundedRect;
task.textAlignment = NSTextAlignmentCenter;
task.backgroundColor = [UIColor whiteColor];
task.textColor = [UIColor blackColor];
task.delegate = self;
task.font = [UIFont boldSystemFontOfSize:fontSize];
[view addSubview:task];
self.tasksArray = [[NSMutableArray alloc] init];
return view;
}
viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
self.tasksArray = [NSMutableArray arrayWithCapacity:0];
self.title = #"Test";
self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[backgroundView setBackgroundColor:[UIColor colorWithRed:227.0 / 255.0
green:227.0 / 255.0
blue:227.0 / 255.0
alpha:1.0]];
[self.tableView setBackgroundView:backgroundView];
}
Remove [cell.textLabel setText:self.task.text];
And then,
Insert [self.yourTableOutletName reloadData]; after [self.tasksArray addObject:task.text];
Now your code will reload the tableView after adding a object into self.taskArray.
And then,
To reflect your array in tablView use this line.
Insert [cell.textLabel setText:[self.tasksArray objectAtIndex:indexPath.row]]; after [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
This line pulls the data incorrectly: [cell.textLabel setText:self.task.text];
self.view = tableView;
It should be from your array.
Also you never reload data, that should be the last line in textFieldShouldReturn

Resources