Why does a UITableView cell.contentView.bounds.size.width change with cell reuse?

I use `cell.contentView.bounds.size.width` to calculate the position of a text field in a UITableView cell. When the cell is created, debug code reports the width as 302. When the cell scrolls off the screen and then back on, the debug code reports that the it is 280--every time. It doesn't seem to want to go back to 302 and stays stuck at 280. The net result is that the text field gets put in the wrong place the second time the field is put into the cell's contentView, though it was put in the right place the first time.
I figure 22 is significant somehow, but I don't know what it is. Guessing it might be the disclosure arrow, I moved the "clear the cell" code up front of the width determination, including setting the accessory to nada.
Can anybody tell me what's going on here?
The code (with irrelevant--that I know of--stuff snipped out) looks like this:
<code>
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
              NSUInteger section = [indexPath section];
              NSUInteger row = [indexPath row];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        // Configure the cell.
        while( [cell.contentView.subviews count] ){
            id subview = [cell.contentView.subviews objectAtIndex:0];
            [subview removeFromSuperview];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    8< snip!
              CGFloat          theCellWidth = cell.contentView.bounds.size.width - 44.0;
              CGFloat theLineHeight = [[UIFont boldSystemFontOfSize: [UIFont labelFontSize]+1.0] lineHeight];
        NSLog(@"cell.contentView.bounds.size.width %1.0f",cell.contentView.bounds.size.width);
        if (0==section) {
                        switch (row) {
                                  case 2:
                    while( [cell.contentView.subviews count] ){
                        id subview = [cell.contentView.subviews objectAtIndex:0];
                        [subview removeFromSuperview];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                                            cell.textLabel.text = @" ";
                                            cell.detailTextLabel.text = @"The Age";
                                            theAgeTextField.frame = CGRectMake(10.0, 2.0, theCellWidth, theLineHeight);
    //                NSLog(@"cell.contentView %@",cell.contentView);
                                            theAgeTextField.text = theAge;
                                            theAgeTextField.font = [UIFont boldSystemFontOfSize: [UIFont labelFontSize]+1.0];
                                            theAgeTextField.keyboardType = UIKeyboardTypeDecimalPad;
                                            theAgeTextField.borderStyle = UITextBorderStyleNone;
                                            theAgeTextField.userInteractionEnabled = NO;
                                            [cell.contentView addSubview:theAgeTextField];
                                            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                                            break;
    8< snip! (lots of closing braces and other stuff omitted)
        return cell;
<hr>
</code>
**Want to try this one at home, boys and girls?**
Start with a new Navigation-based Application. Put the following code into RootViewController.m:
<code>
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
        return 5;
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        NSLog(@"cell.contentView.bounds.size.width %1.0f",cell.contentView.bounds.size.width);
        // Configure the cell.
        return cell;
</code>
There are only two changes in the default code required to make this happen: changing the number of rows in the section ("return 5") and the style of the cell must be _UITableViewCellStyleSubtitle_. Then, when you run the program, you'll see five lines of this:
<code>
    2011-06-18 11:10:19.976 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
    2011-06-18 11:10:19.978 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
    2011-06-18 11:10:19.979 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
    2011-06-18 11:10:19.980 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
    2011-06-18 11:10:19.982 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
</code>
Drag some cells off the screen (drag up--down doesn't do anything) and when they reappear, you get this:
<code>
    2011-06-18 11:10:24.013 TestTableCells[7569:207] cell.contentView.bounds.size.width 320
    2011-06-18 11:10:24.047 TestTableCells[7569:207] cell.contentView.bounds.size.width 320
    2011-06-18 11:10:24.130 TestTableCells[7569:207] cell.contentView.bounds.size.width 320
</code>
Frankly, I'm frustrated as heck with this, and am so very tempted to pony up the $99 (without a working app, even) so I can have somebody at Apple weigh in on this one.
<hr>
Wanna' see something more interesting? Try this in place of the `static NSString...` line:
<code>
        NSString *CellIdentifier = [NSString stringWithFormat: @"%d", arc4random() ];
        NSLog(@"%@",CellIdentifier);
</code>
Now, every time, the width in the log is _always_ 302. It would seem, then, that a reused cell has different content width than the original cell.
Anybody got a clue on this?

Hi,
i guess the reason is that a newly create cell is create with a default frame by initWithStyle:
But it's not yet added to any superview so you're logging that default size.
After returning the new cell the tableViewController adds that cell as subview to the tableView which can lead to a resize of that cell.
If the cell is scrolled off screen it's just removed from superview but stays the same size. If it's reused later it's still having the same size it had when removed from superview.
Dirk
initWithStyle:
But it's not

Similar Messages

  • Why does PDF Optimizer no longer reduce size after CS4 upgrade?

    I've been able to successfully reduce the size of the PDFs created from my Illustrator files for years using Advanced> PDF Optimizer in Acrobat Pro. Upgraded to CS4 last week. Now it seems to have reduced everything, but the files are still huge. When I check Space Audit 96% or more is taken up by "piece information".
    I've tried changing the Adobe PDF presets, the Document Raster Effects settings, and outlining all text in Illustrator to see if that made a difference. Nothing. The frustrating thing is i've done this for years with no problem. HELP?!?!

    From: Riannosda <[email protected]>
    Reply-To: <[email protected]>
    Date: Wed, 22 Jul 2009 07:06:34 -0600
    To: Pamela Myhre <[email protected]>
    Subject: Why does PDF Optimizer no longer reduce size
    after CS4 upgrade?
    Hi, I've found the solution because today it happened to me as well.
    Just go to "PDF Optimizer", then click to "Discard user data" and finally to
    "Discard private data from other applications": in this way you delete any
    information left by Illustrator and your file's size will get reduced.
    It works.
    Good luckThanks so much! That works like a charm!!
    Pamela

  • On my mac why does it take so long to send a Email with an attachment, on my mac why does it take so lone to send a Email with an attachment

    on my mac why does it take so long to send a Email with an attachment, on my mac why does it take so lone to send a Email with an attachment

    It depends on the size of the attachment and the speed of your internet connection.
    Next time you send an email with an attachment do these two things:
    In Apple Mail (I assume you are using Apple Mail), under the Window menu select Activity. Arrange the Activity window so you can see it.
    Then open the separate application located in the Utilities folder called "Activity Monitor" and arrange it so you can see it at the same time as the Activity window in Mail.
    In Activity Monitor program, select the tab labeled "Network." Watch the "Data sent/sec" portion. Then send your email, while watching the Mail Activity window and also the Activity Monitor program window Data sent/sec area.
    You should see the mail being sent with a progress bar in the Mail Activity window and also you should be able to see how many bytes/sec or KB/sec or MB/sec your internet connection is giving you in the Activity Monitor window.
    Example: my internet provider gives me about 20 Megabits per second download and 5 Megabits per second upload. To convert these to Megabytes per second (Activity Monitor shows things in bytes, not bits), simply divide by 10 (not the exact thing to do, but close enough). So I get 0.5 Megabytes per second upload speed. When I send a file that is 5 Megabytes in size, it takes about 10 seconds if I am getting the full upload bandwidth. If I am getting less than that (which sometimes happens), it will take proportionately more time. Either way, you can see what is happening with these two windows.
    If your internet provider is supposed to give you, say, 5 Megabits/sec upload (0.5 Megabytes/sec), but you see only say, 5 KB/sec (=0.005 Megabytes/sec), sent in Activity Monitor, then your emails are taking a long time because you are getting only abut 1/100 the speed you should be. You might want to check with your internet provider about that.

  • Why does my ical on my ipod touch not sync with my ical on my desktop if I put in an event on the ipod calendar?

    Why does my ical on my ipod touch not sync with my ical on my desktop imac ical?
    It will if I put it in on my desktop though.
    Please help,
    Brie

    Probably because you did not tell the iPod to sync the calendar in iTunes.

  • Why does Apple iPad Camera Connection Kit no longer work with iOS8

    Why does Apple iPad Camera Connection Kit no longer work with iOS8?

    The kit is firmly inserted in thhe iPad's dock ? You could also try a reset and see if it's recognised after the iPad has restarted : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.
    I haven't had problems using the kit with SD cards from Canon cameras . What capacity is the card, and it's an SD or SDHC card - if it's an SDXC card that's formatted as ExFAT then it won't be recognised

  • Why does the payment screen for the creative cloud change from english to portuguese?

    Why does the payment screen for the creative cloud change from english to portuguese?
    I'm trying to sign up for the photography creative cloud with lightroom 5 and photoshop. When I click on the "buy" button is takes me to the payment page, but my country changes from the U.S. to Argentina and the language changes also.
    I've tried contacting Adobe, but they're ways of contacting them are a pain in the ***. The chat doesn't work and I'm on hold forever when I call.

    Make sure that EVERY DETAIL is the same in every place you enter your information
    -right down to how you spell and punctuate the parts of your name and address
    Change/Verify Account https://forums.adobe.com/thread/1465499 may help
    -Credit card https://helpx.adobe.com/utilities/credit-card.html
    -email address https://forums.adobe.com/thread/1446019
    -http://helpx.adobe.com/x-productkb/global/didn-t-receive-expected-email.html
    -http://helpx.adobe.com/x-productkb/policy-pricing/change-country-associated-with-adobe-id. html

  • Why does my iPhone 4 not have the panorama feature with the new iOS 6 ?

    Why does my iPhone 4 not have the panorama feature with the new iOS 6 ? Can someone please explain this to me. I was already excited about it.

    That was made available in iOS 5. To update, you may need to connect to iTunes

  • Why does my iMac panic and crash when I scroll with my magic mouse or trackpad

    Question Why does my iMac have kernel panics whenever I scroll with my magic mouse or trackpad

    Sorted....needed a new logic board...£800... thank god for applecare

  • Why does my music on my ipod has red square with a red circle around it

    why does my list of music on my ipod have a red square with red circle by it

    Red square in red circle cannot play songs
    Remove Red Circles with Square in middle
    SOLUTION: Some Music Won't Play After Upgrading Your iPhone To iOS7
    My iPod isn't playing certain songs. Help?

  • Why does Printing a document cause it to be changed?

    When I do page setup, etc, then SAVE the document, and then PRINT the document, the "Changed Bit" in the close box of the document is set, and I cannot just close the document.
    Why does Printing change the document?
    How can I avoid this. (If I save the document, then Print, I do NOT want any further changes)
    Thanks

    Bill,
    Complaints about actual program misbehavior or outright bugs need to get reported directly to Adobe. This is a users to users forum and while Adobe personnel occasionally show up here (much, much less seldom now than in years past) it is extremely unlikely that they will see or take any action on such reports here. (Although there WAS a recent appearance by an Adobe engineer who independently jumped on an issue that certainly did seem to be a bug).
    The kind of thing you've described is annoying and should not happen (yes, lazy programming) but it's interesting sometimes when the explanation for such things reveals intent (rather than ignorance of the apparent defect) in order to solve another problem.
    Want REAL annoyance? How about programs that insist on saving (when closing) simply because the file has been opened! That's very common on Windows. Really, really irritating.
    But this thread has gone beyond any usefulness regarding your observation of a very tiny pimple on a major gem of engineering. And you've locked horns with one of the major irritants on this forum. If you persist, the 2 of you will just appear to be 2 brats squabbling in a mud hole. He likes that. Do you?
    You seem like a nice guy (so far). But it also seems like you like fighting (from this and another thread). It would be interesting to hear more from you. My unsolicited advice? Move on. He will not back down from his childish behavior which is an irritant and embarrassment here to many people. Most of whom simply ignore him and don't stick their necks out like I'm doing now.
    He's shamelessly overindulged by the forum moderator who, with all due respect, seems to possess good judgment in most areas save his handling of certain very caustic and inappropriate "members." here. (Sorry Neil)
    Ramon is knowledgeable, but confuses the strange protection afforded by a keyboard hitched to the Internet as macho proof of bravado and fearlessness. (He's never "met" anyone who can make him stop posting anything he wants to. Isn't that special?)
    On this forum he is not a gentleman. (who knows what he's like in real life? I'll bet he's very different!) Are you a gentleman? Regarding your complaint that you've been insulted, duly noted. I believe most here are on your side. Persist with this for even one more post and you'll have lost your standing. Let it go, COMPLETELY! Start a new thread about something interesting.
    Welcome to the fray.
    Rich

  • Why does Livecycle Designer need to lock scripting on objects with children that are fragments??

    Can someone tell me why Livecycle need to lock scripting on objects with children that are fragments??
    I mean, just because I have a fragment (which you can't edit the script for), why does Livecycle need me to NOT edit say the initialise event on the Main form.
    Yes, I can remove my fragments, edit and reinsert.  Also if the event already has a script, I can edit the xml.  But neither of these are terribly convenient.
    Couldn't there be a better way?

    The purpose of the fragment is to create re-usable or standard components. In most cases the fragment is not created by the same person designing the form and they do not want the from designer to modify any part of the fragment (it is a separate XDP file). There may be code in that fragment that relies on the structure that exists. If you have the rights you can always edit the fragment and when your PDF is created the changes will be picked up.
    If you want to be able to modify the fragment while it is in Design mode sounds to me like you want to add a component to the object library. This will allow you to have a reusable piece of a form that you can modify on a form by form basis. To do this simply build the piece that you want. Lasso the entire form and drag it onto the Custom library. When you release it a dialog will pop up allowing you to name your component. Now on any form design you can drag your new component onto the canvas and all methods/properties and code will come with that component (allowing you to modify it for that form as you see fit).
    Note that you can create your own libraries to hold your components if you see fit. Also if you put your libraries on a shared drive, you can share components between Designers.
    Paul

  • Why does comments.vi stop working when server directory changes?

    With web server root directory set to "C:\Program Files\National Instruments\LabVIEW 8.2\www",
    I point my browser to "http://localhost/cgi-bin/examples/comments.vi" and I get the comment form.
    Next, I quit the G Web Server, set the server root to "c:\ats\www",
    I copy the comments.vi and comments.llb files to c:\ats\www\cgi-bin and point my browser to http://localhost/cgi-bin/comments.vi.  Instead of showing the form as before, I get a dialog box prompting me to either "Open with..." or "Save to disk".  I'm using Firefox.  Why does this happen?  Is there a configuration that I must set up to get the G Web Server to work at other than the default location?

    kc64,
    To your browser, you're looking at a website (served on localhost in this case) and pointing to a specific file (in this case a VI).  Just as if you point your browser to an address of the form www.website.com/file.pdf it will ask you what you want to do with the file--open or save it.  In this dialog box, you should have the option to automatically do what you select for the file type from now on.
    The dialog box itself has nothing to do with changing your server root, it has to do with what your browser is configured (or not configured) to do with the VI file type.  As for why this didn't happen the first time and it's prompting you now, maybe the action got changed for the VI file type.  This can be configured in Firefox by going to the content tab of tools->options.
    Regards,
    Craig D
    Applications Engineer
    National Instruments

  • Why does my iphone 4s shut down by itself even with full charge? It comes back on only when I do a hard reset! Any solutions to this?

    My friend recently gifted me a brand new iPhone 4s bought in the the US. I live in India though. My phone keeps shutting off by itself even when there is full battery. And, it comes back on only with a hard reset. Why does this happen?

    Thank you! I will try restoring it as new. But getting it back to the US for service is going to be a task!

  • TS2771 Why does my 4th gen touch stall when playing songs with Bluetooth connectivity?

    Why does my 4th gen. Touch freeze or stall when connected via Bluetouth?

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:       
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    -  Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • Why does my imac all of a sudden start changing "this computer's local host name"

    why does my imac all of a sudden start indicating that "this computer's local hostname is already in use on this network" and then change the name

    The default of the pref network.http.max-connections has been increased from 30 to 256 in Firefox 6+ versions.
    Try to decrease the value of the pref <b>network.http.max-connections</b> from 256 to 30 as used in Firefox 3 versions.
    *https://support.mozilla.com/kb/Firefox+never+finishes+loading+certain+websites

Maybe you are looking for

  • Regarding Material Determination and free goods determination

    Hi Gurus,              I understand the Material Determination to be substitution of a new material for the old one for any possible reasons such as sales Campaign,non availability etc. Could anyone one explain the concept whether material determinat

  • Creating a vertical dropdown menu that displays inline

    I would like to change how my dropdown menu displays.  First I'd like for it to dropdown directly underneath its menu item and in the process move the other links down.  And remain visible until it is clicked again, thereby shifting other links back

  • Cant get midi out signals

    I use a Yamaha Disklavier as a keyboard connected to Garageband. I can send midi data from the keyboard to Garageband. When I playback the recorded track, I cant get any midi out data to play the Disklavier. When I use other home studio software, it

  • Auto login from other site

    Hi there, There are 2 websites with different database connections and login settings, which uses both the same database. One website is used (among other) to administer the other website, for example adding documents etc. The login on website2 is on

  • Web links (URLs) are being parsed in the conversat...

    I noticed that some of recent updates in skype for mac started to be too clever with links I post in conversations - it tries to fetch the content, parse it and present some small excerpt if it in the conversation.  But I mostly message links to clos