How to show a .xib file in a TableViewCell - objective-c

I have a .xib with an image and a label in the potition that i want..
And i want in the cellForRowAtIndexPath function to set image and label.text then to add then view in the cell and show the cell

Check this:
How do you load custom UITableViewCells from Xib files?
But i do not recommend to load UITableViewCells from xib.
You loose performance on a very critical part.
I recommend to create you UITableViewCell subclasses by code. Because inflating a XIB(XML) during scrolling will create buckings.
If you wan't to have a nice, snappy app, then code instead of XIB (at least the UITableViewCell subclasses).

Related

Custom scrolling drawing layer over UITableView

I've been struggling with this issue for days, so I hope someone can help me out...
I have a grouped UITableView with several cells. I want to draw some custom graphics above the UITableView that would scroll with the content of the table. Specifically, I want to draw a line with dots, joining the UITableViewCells (across the sections) like this:
Of course if we have more cells than what the screen is capable of displaying, the upper layer with the custom drawing should move with the underlaying cells.
I've tried to subclass UITableView and override it's -drawRect method, but it didn't work. Even if I wouldn't call [super drawRect:rect], the table content displayed without problem.
I've tried to add a new subview to the UITableView, but it changes it's size dynamically when it gets the cells and sections from its datasource... I'm out of ideas...
Although the Web is full of custom UITableViewCell samples, I haven't managed to find anything similiar to my concept...
Can anyone help me how to achieve the above mentioned feature?
First your should subclass UITableView. Then create another UIView and add it as a subView of your custom UITableVIew.
Next override the contentOffset property of the UITableView.
-(void)setContentOffset:(CGPoint)contentOffset
{
[super setContentOffset:contentOffset];
// Custom code here. Update custom subview here.
}
This method will be called as the UITableView is scrolled. You can then adjust the offset of your subview and update its drawing.

Proper way to build custom UITableViewCell

I've been wondering about UITableView's and their cells for a while. UITableView is a very handy UIView subclass, but there is a lot of predetermined/forced content on a UITableViewCell. I was wondering what is the best way to create a custom UIView (which will end up being a UITableViewCell) for UITableView?
The cell has a certain style that has to be set and there are predetermined UILabels and accessory views that are completely immutable, other than their contents. I find this to be a big waste, but just giving the cell a custom content view (and background view, if one pleases) doesn't prevent or remove these processes or restore the memory.
Is there any way to create a lighter version of a UITableViewCell subclass? Or is there a way to use a UIView with a selection method instead (other than essentially creating a custom UITableView using UIScrollView)?
Any suggestions would be really appreciated.
There are a few methods:
From a XIB file:
ios steps to create custom UITableViewCell with xib file
http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/
Using Drawing:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318 (4th and 5th examples)
There doesn't seem to be an answer for this. UITableViewCells will always have UILabels and other views automatically added to them. I'm not sure if they are allocated before you set them, though. They may have custom setting / allocation methods.

No content attribute for UITableView in .xib

(XCode 4.2, iOS 5)
In order to reuse a tableview (with a navigation bar and edit/add buttons) I created a UITableViewController subclass with it's own .xib. However, when I add a UITableView to my .xib's main view the content attribute (which I want to set to dynamic prototypes) it doesn't show up. It just shows the sample content (California: Brea, Burlingame, ...). When I add a UITableView in my main storyboard the content attribute does show up.
What is the issue?
For people trying to solve this, it is impossible to set dynamic prototypes cells in a .xib, or even static cells. No embedded sections or cells are supported in .xib files.
If you drag a Table View Controller into a .xib, you'll get an error:
Table views with embedded sections and cells are only supported in
storyboard documents
Xcode 6.3.2

IOS: UITableViewCell

In my project I would create a table view with 10 row, but these 10 rows must be UITableViewCell customizable. Do you suggest links where I can find some suggest code?
The Table View Programming Guide for iOS has three different approaches: Programmatically Adding Subviews to a Cell’s Content View, Loading Custom Table-View Cells From Nib Files and Subclassing UITableViewCell.
Have a look at this tutorial as well.

Re-used UITableViewCell showing old UIImageView for a moment then switches to correct image

So I've built a custom cell for a UITableView. My subclassed UITableViewCell has a UIImageView in it. When scrolling through the table view, as the new cells appear, the "left-over" images from the dequeued cells are shown for a moment until the new image loads in it's place.
I've tried [cell.myImage setImage:nil] but that doesn't seem to have any effect. How can I prevent this problem?
Note that I'm loading the images in another thread (they're coming off the web).
I was able to setImage with a blank png. This prevent the old image from being displayed.
you can also set it to nil