Home News Forum Social Networking Support Us Advertise

Spanish Lesson 1 ($1.99)

aWake!Gently ($1.99)

The Bird & The Snail - Knock Knock - Deluxe ($4.99)

Match-It Trains ($0.99)

Tangled ($0.99)

iFlatter ($0.99)

The 15 puzzle ($0.99)

Tap Forms Database ($8.99)

Higher or Lower Card Game (Hi Lo) ($0.99)

Red Pixel ($0.99)

Time-Shift Radio ($0.99)

Want your application advertised here? Only $10/week!

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)
Senior Member
 
Join Date: Aug 2008
Posts: 154
Rep Power: 1
skinrock is on a distinguished road
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)
Senior Member
 
Join Date: Aug 2008
Posts: 154
Rep Power: 1
skinrock is on a distinguished road
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)
Senior Member
 
Join Date: Aug 2008
Posts: 154
Rep Power: 1
skinrock is on a distinguished road
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)
Senior Member
 
Join Date: Sep 2008
Posts: 1,431
Rep Power: 2
PhoneyDeveloper is on a distinguished road
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)
Senior Member
 
Join Date: Aug 2008
Posts: 154
Rep Power: 1
skinrock is on a distinguished road
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
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


» Advertisements


» Online Users: 170
13 members and 157 guests
aki, Alexman, atsd, BostonMerlin, bret, dejuan, lepetitapps, Neverever, P-atr1k, Raphy, Sekharbethalam, Slecorne, _mubashir
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 8,174
Threads: 20,132
Posts: 89,979
Top Poster: RickMaddy (2,121)
Welcome to our newest member, bret
Powered by vBadvanced CMPS v3.1.0

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