Custom Background Image on Grouped UITableView - objective-c

How would I go about setting a custom background image for a UITableView. The wrench in the works is that the table is a grouped style (rounded top corners for the first cell and rounded bottom corners for the last cell). I would like do this as much in code as possible without relying on images too much.
Ideally, here is the solution, but I have no idea if this will work or not:
Create one custom background image
Apply the same custom background image to every cell
Rounding occurs automatically because it is a Grouped table style
Profit.
Is this how it works (besides the profit part... I am an app developer, after all)? Do I need to re-think my approach or is this possible? How would do what I described (or another approach) in code specific to iOS 5+?
Update
Just to clarify a bit, the main question I'm asking is: Does the rounding still occur on the top and bottom cells even if you are using a rectangular image?

Well I think what you are saying is ok, but I suggest creating a unique cell layout in a .nib file and apply there the background. Then, with initWithNibName you can manage every cell at the UITableView's methods on the ViewController.

Related

NSTableView section banner column with custom height

I am trying to create the following layout with a NSTableView:
A big banner per section on the side and regular text content rows on the right side.
The Image on the left side is the problem. It should behave like a floating section when scrolling (stay below the section header). It seems impossible to have the view part of the NSTableView as each column of a row needs to have the same height.
I already tried a lot of things, but I need some input which is the right direction.
What I tried:
Add the image view as a floating view into the NSScrollView? That seems like a good approach, but it doesn't stick on top while scrolling and the (re)positioning within the table is... tricky. Any hints here?
Add the view into the section header and disable clipping somehow (to make them larger than the section)? Couldn't make that work.
Having a table with NSStackViews per row that host itself tables - that did work, but: Independent selections per table is not what I want.
Ok, I finally found a solution.
The view is added to the floating view container of the NSScrollView that holds the NSTableView. I use the bounds of the row views and translate that to coordinates of the floating view container.
I also modified the selection drawing to make it look good and recalculate the coordinates on animations.

How to draw in code an imageview

I have a problem. I want for each record in my core data database to draw an UIImage view on screen. But the problem is that I want to make a sort of grid. On the link below you see what I want to achieve.
picture
So my question is, how do I draw an image on screen in code. And place those images in a sort of a grid. using a collection view is no option, because the app should be running on all IOS devices.
While you could implement a custom UIView and implement the drawRect: method and draw UIImages there, I suggest just using multiple UIImageViews as subviews on your "main" view. Your view might be embedded in a UIScrollView, or you could use a UITableView with custom UITableViewCells. Whichever is easier is probably related to how you can interact with the view.
Building that one huge image view is something that I'd definitely try to avoid - it costs many many (probably unnecessary) memory, and it might be slow as well. Definitely not very flexible to handle, and a pain to update dynamically.
A quick cheat for something like this is to use a Table View and then in each cell to place another TableView but rotated at 90 degrees.
You can then use this second TableView to display the pictures etc...
This will give you a table that scrolls up and down and then each cell can scroll left to right.
I'd suggest subclassing UITableViewCell and setting it up as a UITableViewDelegate and UITableViewDatasource.
You will also have to remember to rotate the content of these "sub"tables by 90 degrees also so that they are the right way up.
This sounds like a lot of work but if you push the management of the sub Tables into the cells then it actually becomes quite easy.

predict table view scroll destination indexpath

I see UIScrollView has a method to predict final content offset
scrollViewWillEndDragging:withVelocity:targetContentOffset:
and since UITableView is also a UIScrollView, So I want to use this value to calculate the destination Cell while the view is still scrolling/decelerating
I'm trying to loop through all the data and sum up the section headers, cell heights, section footers until the sum exceeds target Content offset. Would it work or is there a better way to do so?
Thanks in advance, any help is appreciated!
Leo
Don't use that method to predict where your table view will end up and try to guess which cells to load content for. Optimising table scrolling, particularly the loading of images, is a well-known problem. Check out this WWDC Video (developer registration required) and Apple's sample LazyTableImages project. Basically, you start background operations to load your cell contents, and update the cells (if they are still on the screen) once your content is loaded. In the meantime, you show placeholder content.
If you do it the way you intend, you will only ever have the target cells populated,which will look odd as you are scrolling past cells that have never been the target.

Core Animation causing partial Source List focus ring

I'm using a slightly modified ImageAndTextCell from one of Apple's tutorials in a custom NSOutlineView. For those unfamiliar with it, it's an NSTextFieldCell subclass that draws an image to the left of the cell's text.
I have a Source List like iTunes's, with group rows, and items beneath. While editing the cell's value, the focus ring only draws partially for the group's first two rows (see below). The top third of the focus ring draws in the first row, and the bottom third draws in the second row.
Subsequent rows draw fine (see the third row below), and they all have the same image. What could be causing this? (See Update 3 below. Core Animation is causing this behavior)
Update 1
I commented out virtually all custom code in ImageAndTextCell and it made no difference (Only init, dealloc, copyWithZone, and the image getter and setter remained).
Update 2
I commented virtually all code in the NSOutlineView subclass, and my delegate class, as well as keeping all code from Update 1 commented out - still strange results. The third row is no longer always perfect, but the portions of the focus rect drawn shifted as I removed various functions.
Also, the items I'm having problems with are in the second of my two outline groups. When renaming the only item in the first group, the focus rect was perfect every step of the way. Ironically, this is the one that can't be renamed during standard operation of my app.
Next I'll take a look at all of my settings in the NIB and see if something might be broken there.
Update 3
I was able to fix it by disabling Core Animation across the board for every view in my window. The question has now become: How do I re-enable Core Animation without making my focus rects look crappy?
Not having solved this before moving to Lion, I can now happily report that switching to a view-based NSOutlineView fixes this problem. Oddly, if you turn on layer-backing in IB for the outline view, it creates other problems. The interface still animates, however, after unchecking those boxes (and has support for far richer animations than the cell-based outline view).

Animating rows in an NSTableView

Is there a simple way of animating rows in an NSTableView?
I'd like to be able to do something like flash a row, or fade out a row.
Essentially - to provide a bit of visual feedback when rows are added or removed.
Edited to add:
I'd had a quick look over Google before posting this; but I wanted to know if there was some way to do this that I'd missed other than drawing and animating parts of the table view myself.
To flash a row, there are a number of ways to go. You could just grab a cell and play with it's view, such as change the color of the background or font colors. You could also just select the cell and deselect it a few times, if you don't care about removing the existing selection from another cell. Or you could superimpose another view on top of the cell's view and use blend modes...
For animating the deletion, you could do the same as above, dimming the cell, or even move the view up and out, transform it so it shrinks down and move it over to a trash can and shrink it all the way down as it enters the trash. Then after the animation is done, you delete the row.