UITableView background has weird behavior - ios

I have a UIViewController with a UITableView, which is showed from the root view controller. In the simulator everything is working fine, but when testing the app on a real device running iOS7, the background of the UITableView is the same image of the root view. Setting both backgroundColor and backgroundView has no effect. I have also tried to set tableView.opaque = NO and setting the background of the cells, but still not results.
Any ideas on how to fix this behaviour?

Try with this piece of code:
contentTable = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
contentTable.delegate = self;
contentTable.dataSource = self;
[contentTable setBackgroundView:nil];
[contentTable setBackgroundColor:[UIColor blueColor]]; // i.e. Bluecolor as backgrounf
This will return a table with a blue background.

Related

Styling separator of table view cells

I have the following code in my willDisplayCell function
//bottom border
UIView* bottomBorderView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height-1, cell.frame.size.width, 1)];/// change size as you need.
bottomBorderView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"dot.png"]];// you can also put image here
[cell.contentView addSubview:bottomBorderView];
It worked just fine in iOS7, but ever since I updated Xcode and started testing the app on iOS8 the borders have been displaying incorrectly. I cant figure out what changed that is causing the issue. The problem seems to get worse the more you scroll.

UISearchBar changes its superview when it is added to UITableViewCell on iOS 7.1

In my project i need an UISearchBar to scroll on an UITableView. So i just put it on an UITableViewCell like this:
searchBar = [[SearchBar alloc] initWithFrame:cell.bounds];
searchBar.delegate = self;
searchBar.placeholder = NSLocalizedString(#"Search friends", "");
searchBar.layer.borderWidth = 1.f;
searchBar.layer.borderColor = [UIColor whiteColor].CGColor;
sdc = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:nil];
sdc.delegate = self;
[cell addSubview:searchBar];
and it works fine on iOS 6. But on iOS 7 it switches to another superview (and literally disappears from the screen) when just getting in focus. At first i thought it's something wrong with my project which causes such a behaviour but then i created a simple test project and i verified this - indeed, it's a rule, on iOS 7.1 UISearchBar added to UITableViewCell moves to another superview and gets lost from the screen right after becoming first responder.
I have overridden willMoveToSuperview: method on the search bar and i see that it moves from UITableViewCellScrollView to a view which class is UIView and whose superview's class is UISearchDisplayControllerContainerView.
After few hours of search and experiments i'm not able to figure out what causes this behaviour and how to escape it. All i know for sure is that it happens right between calls to these two UISearchDisplayDelegate methods: searchDisplayControllerWillBeginSearch: and searchDisplayControllerDidBeginSearch:.
Did anyone ever encountered this? Any ideas how to resolve it?
Are you sure you need this bizarre way to add UISearchBar to UITableViewCell to just scroll it? I simply use smthng like this:
UISearchBar *mainSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
mainSearchBar.delegate = self;
UISearchDisplayController *searchCon = [[UISearchDisplayController alloc] initWithSearchBar:mainSearchBar contentsController:self ];
searchCon.delegate = self;
searchCon.searchResultsDataSource = self;
searchCon.searchResultsDelegate = self;
mainTableView.tableHeaderView = mainSearchBar;

UITableView FooterView background color to clear color doesnt work

i try to set the UITableView Footerview backgroundcolor to clearColor but it stays white, any
other color works fine, any ideas?
_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _incredientsTable.frame.size.width, 60)];
[_footerView setBackgroundColor:[UIColor clearColor]];
Thanks.
Ask yourself these questions:
What do you expect to see through the footer view? Is it the table's background? The underlying view controller's views? In the latter case there are more views between your and the object that you want to be visible under the footer view. That is at least the UITable itself and probably the background of self.view (which in most cases but not all is the table)
You need to set background color of table view in this case.
tblView.backgroundColor = [UIColor clearColor];

table background clear - objective c - cocoa

Hi I want to display my table view without any background color so I used the following code to clear it
[uiTableView setBackgroundColor:[UIColor clearColor]];
This worked fine in the new iPad and also other generation iPads except it failed to work in iPad version one. The table shows with the background gray color. Is this something to do with iOS 5 ? Can anyone let me know if we can clear the background color in first version iPads.
I have noticed the same thing under iOS 5+. Try this:
[uiTableView setBackgroundColor:[UIColor clearColor]];
[uiTableView setBackgroundView:nil];
Should work as intended.
EDIT: If you're using the default cells, they cover the UITableView, so changing the UITableView's background color and view doesn't do anything. Try this in your tableView:cellForRowAtIndexPath: method:
cellName.backgroundColor = [UIColor clearColor];
cellName.backgroundView = nil;
As tableview has one more view as its background. You can set the backgroundColor in two ways.
i) Set the background color for the tableview and set the backgroundView to nil.
[uiTableView setBackgroundColor:[UIColor clearColor]];
[uiTableView setBackgroundView:nil];
ii) Set the backgroundColor for the tableView backgroundView.
UIColor *backgroundColor = [UIColor clearColor];
uiTableView.backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
uiTableView.backgroundView.backgroundColor = backgroundColor;

Change background on a UITableView embedded in a UIViewController on iOS 5

I am trying to change the grey gradient background on an embedded UITableView to the color I have set on the parent view in the Storyboard.
I have been looking around, and found the following threads:
Change iPhone tableview (style grouped) background color while preserving texture
How can I set the background of UITableView (the tableview style is “Grouped”) to use an image?
UITableView backgroundColor always gray on iPad
I have an IBOutlet in the parent controller connecting the two views.
My implementation looks as follows:
- (void)viewDidLoad {
[super viewDidLoad];
[activeShipmentsTable setBackgroundView:nil];
[activeShipmentsTable setBackgroundView:[[[UIView alloc] init] autorelease]];
[activeShipmentsTable setBackgroundColor:UIColor.clearColor];
}
What am I doing wrong?
Thanks.
Try setting et the background color on the table's background view, not the table itself.
UIView *view = [[[UIView alloc] init] autorelease];
view.backgroundColor = [UIColor redColor];
self.tableView.backgroundView = view;

Resources