UISegmentedControl Not Redrawn - iphone

I'm using a UISegmentedControl to show headers for a table view. When the orientation changes, the headers are resized depending on the labels in the table view underneath. Despite being connected up in IB, I have to move the phone around a bit to fire a orientationChanged notification and update the widths. I've even tried setting the first segment width to 0 in IB, then again in viewDidLoad, but all headers are the same width when the view loads. I've tried using performSelector:afterDelay to make sure the view is actually on screen, and also calling setNeedsLayout and setNeedsDisplay, but nothing seems to work. I simply have to jiggle the phone around.
Is this a bug anyone has experience with or am I making a daft mistake?
I'm setting the width as below:
[segSortOrder setWidth:0.0 forSegmentAtIndex:0];

The only solution I came up with for this was to use performSelector:afterDelay and using self.view.bounds.size.width with a variable amount of padding (how much is trial and error for each ViewController. Not ideal but it does the job.

Related

iOS - resize UITableView height programmatically

I'm having a problem trying to programmatically resize the height of a UITableView hosted within a UIViewController, using iOS5 and Storyboards. The VC displays a master/detail record style with the UITableView displaying the detail records. Depending on the type of master record shown, a set of buttons may be needed at the foot of the screen. If the buttons are not needed then I want the UITableView to extend it's height to take advantage of the space available. I'm using the following code :
CGRect tableFrame = [tableListView frame];
if (blnApprovalRec == YES)
tableFrame.size.height = 127;
else
tableFrame.size.height = 170;
[tableListView setFrame:tableFrame];
This code is called whenever the master record changes, including when the screen first loads in viewDidLoad. The problem is that when the VC loads, the UITableView doesn't paint using the size specified - it just paints with the default size from IB. Once the user changes the master record so the table is reloaded then everything works fine and the size changes as required. I've tried forcing a repaint using setNeedsDisplay, setNeedsLayout and reloadData but none of these worked.
The problem is that when the VC loads, the UITableView doesn't paint using the size specified
This happens, when table view is loaded, but it's UI is not getting refreshed. Please verify if you have forcefully called in viewDidLoad or viewWillAppear.
Hopefully your this code is in seperate method:
CGRect tableFrame = [tableListView frame];
if (blnApprovalRec == YES)
tableFrame.size.height = 127;
else
tableFrame.size.height = 170;
[tableListView setFrame:tableFrame];
When the view appear initially, you may have the default selected value from master record.
You can set that value/instance in calling function in viewWillAppear.
Can you show method name and code for, how you are calling above snippets of code forcefully?
You can resize UITableView programmatically but you need to create UITableView programmatically too. Don't use Storyboard.
I had the same issue, just needed to move the code from
- (void) viewDidLoad
to
- (void)viewDidAppear:(BOOL)animated
This is tricky, its hard to resize things like this dynamically.
i would try "setNeedsLayout" And "setNeedsDisplay" for your table, and your screen to force a redraw.
Other than that, I would storyboard it to the minimum size and use code to expand it.
Generally apple doesn't like us doing this, your buttons should be drawn over the top of the view inside another view, if thats possible.
Sorry I can't be more precise but I have solved all these issues by mucking around and with hacks, and giving up on resizing things and doing re-designs. Please let me know how you go though :)
Make sure you are setting the frame after the table has loaded.
Which method do you call that code in?

UITableView separators disappears?

in my uitableview, i subclassed uitableviewcell's, and i added a subview to the contentview with flexible width and height. the cells are of dynamic height.
when the tableview first loads, everything is fine. however, as i start to scroll around, separators start disappearing, and they happen at the same places every launch. scrolling around some more will recover the lost separators.
anyone else encounter this?
I don't know how specific this will be to your project, but I'll tell you what I figured out. Overriding my layoutSubviews method was the problem. I looked at the view hierarchy of my cell before and after I called [super layoutSubviews] and discovered that this method was making the contentView 1 pixel shorter and added a new view below it 1 pixel high with a background color of 0.88/0.88/0.88.
If you can't live with some of the side effects of the superclass implementation, it looks like this view must be added manually.
The problem was related to the dynamic heights. Using either ceilf or floorf solved the problem.

iPhone UIImage overlapping text

I have a view with a UIScrollView, UIImageView for a background, and a UITextView. I have created several other views just like this and they all come out okay - with a background image and scrollable text but for some reason, now I can't make that work. Either my image overlaps all of the text so that I can't read it or the UITextView default background (white) shows up so that the user can't see the background image. What could be causing this problem?
Do you use Interface Builder or build the views hierarchy in code?
In both cases you should make sure that the order of your views is correct.
In IB the view that you want to appear on top of all the rest has to be under the rest of the views.
In code, make sure that the text view is the last to be added to the hierarchy.
You could also use the next code in order to check if this is the problem:
[self.view bringSubviewToFront:textView];
Okay, it must have had something to do with choosing the delegate. I can't say that I completely understand how I fixed it but it had to do with declaring the delegate in IB.

UIPageControl render quirk with UIScrollView

I'm building an iPhone application and like most I am trying to implement a UIScrollView with a UIPageControl, however I am coming across a very quirky behavior, which I assume may be a bug. Hopefully one of you has seen this before because it is driving me nuts.
Basically, the page control works fine, everything is hooked up and works normally on all accounts EXCEPT, with certain placements of the UIPageControl within the UIView, the UIPageControl will cease to render.
I'll just take screenshots of the XIB window to help illustrate... here's a placement that works perfectly fine:
http://www.jasconi.us/prob1.png
The UIPageControl is placed physically above the UIScrollView. Works great, everything is visible and working.
The next two DO NOT work:
http://www.jasconi.us/prob2.png
http://www.jasconi.us/prob3.png
The first one is simply placed below the scroll view. Doesn't render at all.
The second one is placed above the scroll view without technically being inside of it. Also doesn't render.
What the hell is up with this? I've tried using
[[self view] bringSubviewToFront:pageControl];
...to no avail.
Any ideas?
OK I found the answer to this, it's a little six degrees of Kevin Bacon.
This isn't actually a software bug, but a XIB quirk, for some reason the lower placement of the page control in combination with the default settings for autosize and anchor seem to jettison the control into outer space.
If you turn off all auto-scaling and auto-sizing and auto-anchoring and all that other crap, the controls appear exactly as you expected. The fact that it appears reliably when placed above the ScrollView is an oddity.
shrug.
Hope this helps future iPhone initiates.
Did you check to make sure that numberOfPages is not 0?
If you set a breakpoint can you see that pageControl is not nil?
I was still encountering this exact same problem, even after trying everyone's posted answers. My issue ended up being a little more "DOH":
I was using UIPageControl at the bottom of a modal FormSheet, however, I forgot to set the size of the view as Form Sheet in the xib. This caused my page control to be off the screen and never visible.
Moral: set view size (Full, Form, Page, etc) in your xib on the base view.
This will sound like a real no brainer, but I got caught out by it.
By default, UIPageControl expects to be on a dark background. IE: The dots are light gray, and white for the current page.
I used UIPageControl on it's own with no scrollview to change the time range of a graph I was rendering with drawRect:
Long story short, the graph background was white, so the page controller worked, I just couldn't see it. The solution was putting the graph itself in a subview, and making the parent that contained the page control have a dark background.

Broken cell with an odd strikethrough?

I'm having a weird issue with a particular UITableView in my iPhone devel experience here. If you look at the following screenshot:
alt text http://dl-client.getdropbox.com/u/57676/brokencell.png
you'll notice a strike through going through the middle of the 'Jane Aba' cell.
Any idea what might be causing this odd graphic display? It's true for both the simulator and for the actual device running 2.2 SDK.
As requested, here's my -tableView:cellForRowIndexPath: method:
* EDIT *
I've located the problem. I'm not entirely sure why this is the problem, but it is. In my RootViewController, I have the following line of code in my -initWithCoder: method:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
When I comment that out, the cell (which is not in the RootViewController, but a secondary controller) it's resolved. Any idea why this might be the case?
I've had a similar problem. For me, the single line was caused by a superfluous view that was created but never sized or placed correctly and so was 1 pixel high, floating over everything else. You can also cause this by confusing a UINavigationController about its set of subviews (by adding views directly to its layout container).
Look through your UI (xib files and programmatically created views) for a view that shouldn't be there or is otherwise not being used. It might be helpful to write some code to dump a UI Hierarchy, so you can see what views are where.
Are you doing anything special in your -tableView:heightForRowAtIndexPath: method?
It looks to me like the height of the row is being set incorrectly, so the contents of the cell are expanding outside of its bounds.
The problem disappears when you set the cell height for the table view to 1 pixel in IB. It seems that before you populate the table, an empty table is drawn with the outlines of the cell height set in IB.
Don't set the cell height to 0. IB doesn't like that. :-)