How to fix border in UITableView for the UITableViewStyleGrouped - iphone

For a UITableViewStyleGrouped UITableView a small extra line is drawn below the tableview
How do I fix this?
I have tried my best. No luck so far.
Thank's in advance.
My Code
-(void)myTableView
{
// if(mytableView != nil)
// [mytableView release];
if (mytableView == nil) {
mytableView = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped];
}
mytableView.delegate=self;
mytableView.dataSource=self;
mytableView.backgroundView=nil;
mytableView.scrollEnabled = FALSE;
[self.view addSubview:mytableView];
[self myPortraitMode];
}
Background of the table is fixed is an image.

I think what you are referring to is the Bevel color of the table view.
The answer is in this post.
Basically, you need to set the table separatorStyle to UITableViewCellSeparatorStyleNone or to UITableViewCellSeparatorStyleSingleLine.

You need to set a background view:
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor yourColor];
tableview.backgroundView = backgroundView;
[backgroundView release];
You don't need to set the properties every time.
-(void)myTableView
{
if (mytableView == nil) {
mytableView = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped];
mytableView.delegate=self;
mytableView.dataSource=self;
mytableView.backgroundView=nil;
mytableView.scrollEnabled = NO;
[self.view addSubview:mytableView];
[self myPortraitMode];
}
}
I don't really see what the problem is though.

Related

programmatically added tablview's scroll disabled

I added tableview to scrollview programmatically but it is not scrolling. While i tried the same using XIB. but it is working fine.
here is my code
CGRect frame = CGRectMake(30, 30.0f, 900, 300.0f);
eappTable = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
eappTable.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
eappTable.delegate = self;
eappTable.dataSource = self;
eappTable.scrollEnabled = YES;
eappTable.scrollsToTop = YES;
[eappTable reloadData];
[scrollView addSubview:eappTable];
eappTable = [[UITableView alloc] nitWithFrame:YourSize style:Table_Style]];
eappTable.delegate = self;
eappTable.dataSource = self;
eappTable.scrollEnabled = YES;
[scrollView addSubview:eappTable];
And set self.scrollView.contentSize
You have to set the Content Size of ScrollView.
Hope it Helps !!!
Try to enable bouncing (because if all cells size are smaller than the uitableview size it self, it won't scroll if bounce is set to NO) :
eappTable.bounces = YES;
[eappTable setContentSize:CGSizeMake(320, 680)];
I know this is not the answer you are looking for. But I would like to mention one point :
Never add tableview as the subview of your scrollview.
Important: You should not embed UIWebView or UITableView objects
in UIScrollView objects. If you do so, unexpected behavior can
result because touch events for the two objects can be mixed up and
wrongly handled.
From UIWebView Class Reference

Hide a UITableView of a UIScrollview on a button click in iPhone

I have a UITableView with some data in -(void)ViewDidLoad. So it appears accordingly. But when I click a button then my tableview should be hidden and I should load a UIlabel with some text.
But for me on button click empty tableview with some rows is loading. I should avoid it. How can I do it?
Here is my code
-(void)ViewDidLoad {
tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,380,320,200) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
-(void)DatePickerDoneClick:(id)sender {
[tableview setHidden:YES];
displayError =[[UILabel alloc]init];
[displaytError setFrame:CGRectMake(20,400,320,100)];
displayError.textAlignment=UITextAlignmentLeft;
displayError.backgroundColor=[UIColor clearColor];
displayError.text=[NSString stringWithFormat:#"Not found"];
[self.view addSubview:displayError];
}
Could not get where I'm going wrong?
To hide Table View you can use
myTableView.hidden = YES;
or
[mtTableView setHidden:YES];
Hope this will help you out.
if tableview.hidden = YES; is not doing the job
try the next code:
[self.tableview removeFromSuperView];

need an advice with orientation change iphone

my problem might be simple to some of you but i can't find a solution. I have a method where a create my views automatically (text fields, labels and text views). It's like a registration form. The problem is that when i change the screen to landscape mode, i want to change the views width. To do that i used [self.view removeFromSuperview] and created the views again. The problem is that the views won't get recreated with the landscape width. I can't use IB to autosize the views at orientation change. The views are created in viewDidLoad and removed and recreated in - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {} I don't know why they don't get recreated after being removed. If there was another solution that you could share with me i would appreciate it.
Here's how i create the views:
-(void)createViews:(int)width
{
for(int i = 0; i < numberOfTextfields; i++) {
textfieldPadding = textfieldPadding+40;//set some space between the text fields
labelPadding = labelPadding+40;//set some space between the labels
UITextField *field = [[UITextField alloc] initWithFrame:
CGRectMake(10,i*textfieldHeight+textfieldPadding+firstTextfieldHeight+10,width, textfieldHeight)];
field.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//field.backgroundColor= [UIColor cyanColor];
field.placeholder = [labels objectAtIndex:i];
field.borderStyle=UITextBorderStyleRoundedRect;
field.returnKeyType = UIReturnKeyDone;
[field addTarget:self action:#selector(doneButton:)
forControlEvents:UIControlEventEditingDidEndOnExit];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, i*labelHeight+firstLabelHeight+labelPadding-20, width, labelHeight)];
label.text = [labels objectAtIndex:i];
//label.backgroundColor = [UIColor brownColor];
[scrollView addSubview:field];
[scrollView addSubview:label];
[textfields addObject:field];
[labels addObject:label];
[field release];
[label release];
}
}
Here's where i wanted to remove them and recreate them:
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
{
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
[self.view removeFromSuperview];
[self createViews:landscapeWidth];
}
else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self.view removeFromSuperview];
[self createViews:portraitWidth];
}
}
Thanks in advance!
Instead of removing, resizing and then re-adding as you currently are why not just set the appropriate autoresizingMask (link) when you create the view initially?
UITextField *myTextField = [[UITextField alloc] initWithFrame:someRect];
// the following will automatically resize the width on orientation change
myTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[myView addSubview:myTextField];
[myTextField release];

Background image for MoreNavigationController

I'd like to place an image behind the tableView in my UITabBarController moreNavigationController. I have tried inserting a subview like so when first setting up the TabBar:
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background3.png"]];
[self.tabBarController.moreNavigationController.topViewController.view insertSubview:imageView atIndex:0];
But this places the image over the top, presumably because the tableView isn't there at the time. Is there a better time when I can call this in order to have it work properly, or an easier approach?
With some assistance from this question, I figured out how to do this. Basically, the viewController in the moreNavigationController is a single TableView, so adding a background image won't work. What I need to do was to create a new view, add the background image, and then add the moreNavigationController view on top of that. I did this by overriding viewDidLoad in a subclass of UITabBarController, but I expect it could be done elsewhere as well.
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *moreController = self.moreNavigationController;
if ([moreController.topViewController.view isKindOfClass:[UITableView class]]) {
UIView* newView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,367)];
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background3.png"]];
imageView.opaque = NO;
imageView.alpha = 0.4;
[newView addSubview:imageView];
moreController.topViewController.view.backgroundColor = [UIColor clearColor];
moreController.topViewController.view.frame = CGRectMake(0,0,320,367);
[newView addSubview:moreController.topViewController.view];
moreController.topViewController.view = newView;
}
}
You could probably be smarter with the frame sizes, etc, but this works for me. Hopefully it helps someone else too.
Now you can acess backgroundView property from UITableView subclasses .
UIViewController *moreViewController = tabBarController.moreNavigationController.topViewController;
img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"BG_MORE+1.png"]];
//Got some crashs in initialization !! Need to check .
if ([moreViewController.view isKindOfClass:[UITableView class]]) {
UITableView *moreTableView = (UITableView*)moreViewController.view;
[moreTableView setBackgroundView:img];
}
Besides all the dotty mess here, you can use UIView's bringSubviewToFront: and sendSubviewToBack: to organize your subviews. Basically this should help, although if you have more subviews you will need to play around with it a little bit:
[self.tabBarController.moreNavigationController.topViewController.view addSubview:imageView];
[self.tabBarController.moreNavigationController.topViewController.view pushSubviewToBack:imageView];
//or [self.tabBarController.moreNavigationController.topViewController.view bringSubviewToFront:tableView];

How to add a custom background to UISearchDisplayController's table view?

I want to add a custom UIImageView to UISearchDisplayController's table view background and set table view's background color to clearColor. Tried a few different approach but couldn't find the right solution. Any idea how to approach this?
Note: I don't want to add to searchDisplayController's searchResultsTableView's view hierarchy, but rather overlay another sibling view below it)
You can set the background image in a similar way you would for your main table, only set it in the searchDisplayControllerDidBeginSearch delegate method. For instance:-
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[controller.searchResultsTableView setDelegate:self];
UIImageView *anImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"gradientBackground.png"]];
controller.searchResultsTableView.backgroundView = anImage;
[anImage release];
controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
controller.searchResultsTableView.backgroundColor = [UIColor clearColor]; }
You can also do this wherever you instantiate your UISearchDisplayController. In my app I was doing this in my UITableView viewDidLoad method and was matching the styles between the two tables:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.separatorColor = [UIColor blackColor];
self.tableView.backgroundColor = [UIColor grayColor];
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
searchController.searchResultsTableView.separatorColor = self.tableView.separatorColor;
searchController.searchResultsTableView.backgroundColor = self.tableView.backgroundColor;
searchController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
}