Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone ($4.99)

dotnetIQ ($4.99)

Your First iPhone App ($1.99)

iPocket Tools 9 in 1 ($0.99)

Catch-Me (Free)

Alien Strike ($0.99)

Historic Olympic Medal-Table ($1.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 03-13-2009, 01:43 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 34
Default Question about UITableViewCell and grouped tables

OK, so I am making reasonable progress on my app, but have experienced some very strange behavior populating a UITableView with 3 sections. I should mention that I have created custom UITableViewCell views in IB and am using a table view cell factory to instantiate table cells (ala. this post: Using UITableViewCell with InterfaceBuilder « Agile Developer, Berlin, Germany)

In the top section, I have one cell with some "header" information that includes a UIImageView and some labels. in the cellForRowAtIndexPath delegate method, I get data from my model and set the text of the labels and set the image data for the UIImageView. The label text is set correctly, but when the table is rendered, the UIImageView is shifted down and to the right from where it is declared to be in IB, obscuring some of the labels in that cell.

In the second section of the table, I have a single cell with a UILabel and a UIButton. For the life of me, I cannot get the label and button text to reflect the assignments made in the cellForRowAtIndexPath delegate method. The text rendered in the simulator is the same "place holder" text that you set in IB. The text getting assigned to the label and button is correct; I have verified this in the debugger. Are there any special release/retain considerations when using the [NSString stringWithFormat:] method?

In the 3rd section, I have a list of cells that include a UIImageView and 2 labels. In these cells, the label texts are set correctly.

What could be the reason for the image shift and the label text?

Thanks,
-MrB
mrbelk is offline   Reply With Quote
Old 03-13-2009, 03:05 PM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Image shift is probably because you're not setting the autoresizeMask and/or row height correctly.

The wrong label text should be simple to figure out. Setting the correct label text depends on having the correct label and the correct text. Almost certainly one of those is nil or invalid. Possibly you're using the wrong tag or you didn't set the tag in IB.
PhoneyDeveloper is offline   Reply With Quote
Old 03-13-2009, 03:26 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 34
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
Image shift is probably because you're not setting the autoresizeMask and/or row height correctly.

The wrong label text should be simple to figure out. Setting the correct label text depends on having the correct label and the correct text. Almost certainly one of those is nil or invalid. Possibly you're using the wrong tag or you didn't set the tag in IB.
The tag thing is part of the solution. I was tagging the stuff contained in the UITableViewCell starting with zero, but it would appear that the UITableViewCell itself reserves zero for itself, so subviews have to start at 1. The image shift is fixed now, as is the label text in the 2nd section, but the button text is still the placeholder text.

What is the "correct" way to set the title of a button using that UIControlState enumeration? Should the state really only be UIControlStateNormal, or should it be an OR'ed combination of Normal, Highlighted, and Selected?

NVM: I figured out what I was doing wrong with the UIButton title.

Thanks,
-MrB

Last edited by mrbelk; 03-13-2009 at 03:40 PM. Reason: found solution
mrbelk is offline   Reply With Quote
Old 03-13-2009, 04:23 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

A tag of zero is the default tag for any view that doesn't have a tag set. You need to use other values than zero.

The control state is a little confusing. You almost never want to or the enums together, at least not unless you really understand what that means.
PhoneyDeveloper is offline   Reply With Quote
Old 03-13-2009, 04:30 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 34
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
A tag of zero is the default tag for any view that doesn't have a tag set. You need to use other values than zero.

The control state is a little confusing. You almost never want to or the enums together, at least not unless you really understand what that means.
Thanks. In the windows world, you can usually "OR" enums together that are meant to be different parts of the same behavior (enums decorated with the "Flags" attribute, like messagebox properties). I thought I had seen somewhere where the bitwise or was used w.r.t. control states. I just set the text for the Normal state, since I don't really need any different behavior for the highlighted or selected states.

Thanks again,
-MrB
mrbelk is offline   Reply With Quote
Old 03-13-2009, 05:19 PM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Yes, we in the iPhone world can OR together enums also.

It's just that in this case when you OR together the enums it means something different than what you think it means. So don't do it unless you understand it.

Set the text for the different states individually.
PhoneyDeveloper is offline   Reply With Quote
Reply

Bookmarks

Tags
uitableview, uitableviewcell

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
» Stats
Members: 21,510
Threads: 35,793
Posts: 156,804
Top Poster: smasher (2,449)
Welcome to our newest member, dmf1978
Powered by vBadvanced CMPS v3.1.0

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