A UICollectionView bug? - ios

I have a UICollectionViewController while doing the following:
Return a string array in collectionView:indexPathForIndexTitle:atIndex:
Set cell.contentView.backgroundColor = [UIColor redColor] on collectionView:cellForItemAtIndexPath:
(Notice that changing the background color of the cell is just for demonstrating the issue. The important thing is to show index titles on the right.)
The result (as following displayed) is that the content view takes the entire collection view width and it doesn't being affected (as it should) by the appearance of the index titles.
With UITableViewController I am doing similar steps:
Return a string array in sectionIndexTitlesForTableView:
Set cell.contentView.backgroundColor = [UIColor redColor] on tableView:cellForRowAtIndexPath:
Here, in contrast to the collection view behavior, the content view is "shrinking" as expected as following appear:
Can anyone tell if this is a bug or the expected behavior?

your question is not clear and obvious, but i will try to answer.
First: try to set UITableView's (actually UIScrollView's) property 'showVerticalScrollIndicator' to false (https://developer.apple.com/documentation/uikit/uiscrollview/1619405-showsverticalscrollindicator?language=objc)
Second: try to play with TableView 'contentInset', 'separator inset' properties. Perfectly, you should set 'separatorStyle' to 'none' and use your custom separator-cells, or conditionally set bottom line inside cells (https://developer.apple.com/documentation/uikit/uitableview/1614909-separatorstyle)
Third: check out how to customize Header of Table or Header/Footer of Collection:
https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614901-tableview
https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/1618037-collectionview
One more important thing: you may always Examine a View Hierarchy. Check out this link https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/ExaminingtheViewHierarchy.html

Related

Change color of the area below the last section of a uitableview

I have a UITableView. I figured out how to change the background color for the section headers. However, it also changes the bottom area that contains "no section/rows" to the same color. I don't want this.
Is there anyway I can set the color of that area to be a different color than the section headers?
See example picture for more information.
Any help is greatly appreciated. I've done research but I haven't found anything yet.
Basically, what I had to do was:
In Interface Builder, change the color of the view to what you want displayed at the bottom.
I used the same color that I had set for my table cell rows.
For the section headers:
In the willDisplayHeaderView method, do:
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.contentView.backgroundColor = [UIColor blueColor];
Please note: If you get a white/gray line above the section header - this deals with the footer. So, in viewDidLoad method, set the table footer height to 0:
self.tableView.sectionFooterHeight = 0.0;

setting background in tableview when empty data

My question is how can I implement a background when the tableview is empty like this:
http://pttrns.com/categories/35-empty-data
I tried to setup an UIImageView as backgroundView for the tableView but it appears always mixed with the empty cells.
Thank you in advance fo your help.
Regards,
Victor
You are going to have to turn off the cell separator and set your empty cells to a clear background color.
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
If you set a TableViewFooter to the UITableView, no cell will be drawn. This way, your image should be visible without mixing with any cells.
Alternatively, you can put the image in a special cell and use that cell as TableViewHeader that only gets added when you have no data.
Just cover the table view with a new view that says there's no data. Hide it when there is data.
set an UIImageView behind the table... then at viewwillappear.. if there is no rows for the table.. then set
self.tableView.hidden = YES;
hope it helps... GL HF

monotouch UITableView SectionIndexTitles brakes custom cell's background

I'm experiencing really strange issue with monotouch SectionIndex side panel. Basically after adding
public override string[] SectionIndexTitles (UITableView tableView)
to my table data source, I can see side index being correctly populated, although it cuts a bit of my custom cell's background, which makes it look a bit weird (see image below)
I've got UITableView.Appearance.BackgroundColor = UIColor.Clear set in AppearanceManager, which by look of it, SectionIndex inherits, although what I want is to get SectionIndex to stay "on top" without affecting anything below it including my cell's background image.
Am I missing some property that needs to be applied to UITableView?
I spent ages trying to figure out what's missing, but not getting anywhere with it...
Thanks!
screenshot - http://blue-and-orange.net/media/30659/untitled.jpg
OK I found the problem!
Background should not be assigned directly on cell's BackgroundColor property, instead BackgroundView in your custom cell needs to be assigned to - new UIVIew() (which has the background set)
UIView backgroundView = new UIView();
backgroundView.BackgroundColor = UIColor.FromPatternImage(Resources.CinemaListingCellBackground);
BackgroundView = backgroundView;

Avoid auto resize of uitableview cell content view on entering edit mode

I have a uitableviewcell with content view containing some custom view.'
When the table view enters edit mode the content view resizes (becomes narrower) there by the image in the content view is shrunk horizontally
Does anyone know how to prevent this ?
I have set the cell indentation to none.
Thanks
Have you tried setting shouldIndentWhileEditing to NO
Take a look at properties :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html
Have you tried setting the auto-resize masks on the view?
theView.autoresizingMask = UIViewAutoresizingNone;
You may need to set it on the content view and/or the image view - it's not clear exactly how your view hierarchy is structured. However, the frame might be set explicitly (rather than auto-resized) by the framework, in which case this won't work.
If you are trying to have a background image for the entire table cell, you may also want to try an alternative method which is to set the backgroundColor of the cell like this:
UIImage* someImage = [UIImage imageNamed:#"someImage"];
cell.backgroundColor = [UIColor colorWithPatternImage:someImage];
Remember to make sure the backgroundColor of all other views you place inside are [UIColor clearColor] so that you can see through to the background image.
You can always get a tableviewcell with an indexpath. Using that tableviewcell reuseidentifier, You can avoid the tableview cell content size to be resized or not. I had a requirement to implement the similar kind of functionality to avoid resizing of seperate cells. PFB the code.
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
BOOL shouldIndentWhileEditingRow = NO;
UITableViewCell *lTableViewCell = [tableView cellForRowAtIndexPath:indexPath];
/*Change the position of the target rect based on Sending messages or Receiving messages*/
if ([lTableViewCell.reuseIdentifier isEqualToString:#"SendingChatCellIdentifier"]) {
shouldIndentWhileEditingRow = NO;
}else if ([lTableViewCell.reuseIdentifier isEqualToString:#"ReceivingChatCellIdentifier"]){
shouldIndentWhileEditingRow = YES;
}
return shouldIndentWhileEditingRow;
}
I did something similar to avoid the cell content to be resized when using cell automatic dimension.
My problem was that the textView inside the cell, after the selection, was wrapping its content in more lines, and I just wanted to avoid this.
To solve this "issue":
I added a trailing constraint of 40px (the size of the accessory view) to the cell content
On cell select, i change the constraint to 0, so the text is 40 px larger, but as the accessory shows up, you don't see any changes.
The pro of this solution is that the content dimension is not changing anymore when user select a row.
the con is that you have always 40px of free space on the right of the cell, also when not selected.

custom searchResultsTableView

I am looking to have custom UITableViewCells for my UISearchDisplayController. The searchResultsTableView is a readonly property. I have the delegate and datasource for the searchviewcontroller returning the custom cells, however, it seems to still be using the searchResultsTableView cells. What's the best way to have the search results using my own UITableViewCells?
When a search begins, a whole new UITableView is created. This new table view will use default settings and won't match your table view. In your UISearchDisplayDelegate, override searchDisplayControllerWillBeginSearch: in order to re-theme the new UITableView, like this:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
// Re-style the search controller's table view
UITableView *tableView = controller.searchResultsTableView;
tableView.backgroundColor = [UIColor blueColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
I'm not sure I fully understand the question, but it sounds like you want two different UITableViewCell types (subclasses?) to be returned when you're typing a search, or when you're not searching. Is that right?
Like John said, and depending on how you hooked up the UISearchDisplayController, both the search results table view and your default table view will fire cellForRowAtIndexPath and willDisplayCellForRowAtIndexPath. In those methods you can check which tableView is asking for the cell and customize it as necessary. I customize the background, text and color of my cells and this approach works well for me. I can post code if you'd like.

Resources