Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-12-2008, 09:37 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 158
Default Custom UITableViewCell

I have a view xib that contains just a UITableView, which loads fine, I have it listing out data from my database. But I want to use a custom UITableViewCell, so I added one to the same xib. The reason is so that I can design it in Interface Builder instead of trying to code it.

I changed the class of the ListViewCell to a class I created that extends UITableViewCell. I've tried two ways of allocating this class in the cellForRowAtIndexPath method. First I tried:

Code:
cell = [[[ListViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
But that doesn't seem to use the design from within Interface Builder.

I then tried setting an IBOutlet on my UITableViewController class, and linked it to the TableViewCell using IB, and then this line:

Code:
cell = [[listViewCell initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
But as you might imagine, it doesn't properly create a new ViewCell for each row, it gets messed up: the first two become blank and only the last row actually has a design to it.
skinrock is offline   Reply With Quote
Old 09-12-2008, 09:39 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 158
Default

Basically I was looking for something similar to initWithNibName, but that's not available on UITableViewCell.
skinrock is offline   Reply With Quote
Old 09-12-2008, 10:26 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 158
Default

I thought I was on the right path, but no luck so far...here's what I tried:

Create another UIView set: UIViewController class, UIView class and a xib file, set the propreties in the xib to the respective classes.

In the initWithFrame method for the UITableViewCell class that was created previously, add this:

Code:
CGRect tzvFrame = CGRectMake(0.0, 0.0, self.contentView.bounds.size.width, self.contentView.bounds.size.height);
ListViewCellController *listViewCellController = [[ListViewCellController alloc] initWithNibName:@"ListViewCellView" bundle:nil];
listViewCellView =[listViewCellController.listViewCellView initWithFrame:tzvFrame];
listViewCellView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:listViewCellView];
I thought that might work, but no luck. What's odd is that I get no errors, just a blank cell.
skinrock is offline   Reply With Quote
Old 09-12-2008, 11:07 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Using alloc/init or loading a nib are orthogonal methods for creating objects. Use one or the other. If you load a nib you get one of each of the objects that are freeze-dried in that nib. If you need more than one you need to load the nib again, and again.

It's possible that you could create a nib that holds a single instance of a UITableViewCell subclass and then load that nib many times using the apis in UINibLoading.h. If you like that method then it should work fine. I agree that laying out a UI in code is so 20th century.

Having said that, I generate my UITableViewCells in code. You seem to be mixing these two strategies with no good results. Give that up. One or the other.
PhoneyDeveloper is offline   Reply With Quote
Old 09-12-2008, 11:27 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 158
Default

Well I gave up, I'm just going to lay it out programatically. I'm not about to waste time over this when I have the rest of the app to build.
skinrock is offline   Reply With Quote
Old 08-24-2009, 09:03 PM   #6 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 2
Default

In IB create the UItableviewcell and save it. Select write class files under menu and add it to the project.

you have to write the initwithcgrectframe ( dont remember the exact function name) by yourself and in the initialization function do this:

if(self=[ super init])
{
self=[ [ [ NSBundle mainBundle ] loadNibNamed:@"NIB name without extension" owner:self options:nil] lastObject];
}
return self;

that should do the trick
ifonecoder is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,296
Threads: 39,091
Posts: 171,393
Top Poster: smasher (2,575)
Welcome to our newest member, Issue
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0