UITableViewCell incorrect width on iPad - iphone

We have a modal view that contains a Table view that contains UITableViewCells used to edit an item. On the iPhone everything works fine, but on the iPad we're unable to get the UITableViewCell to register as anything besides 320 px wide. It will basically display correctly, but the items inside of the cell align as if it were only 320 px wide, and anything outside of 320 pixels does not respond to any touch events.
I've gone up the view hierarchy to see if possibly there is a view stuck at 320 px that might be forcing the table view cell to think its only 320 pixels wide, but we can't find anything.
We also even tried presenting the modal view in the main window to ensure it was presented at the highest level:
[appDelegate.tabBarController presentModalViewController:myEditor animated:YES];
I've checked the frame of the tabBarController, the "myEditor" view controller, and everything else involved and they all seem to be correct. The only issue seems to be the tableview cells.
Any help would be greatly appreciated. Thanks!

We found the best way to do this is to subclass the cell and override layoutSubviews (and remember to include [super layoutSubviews]). This has seemed to generally work in most situations.

Related

View reloads incorrectly after rotation

I have a problem reloading a custom UIView (SBBarChart) inside of a table cell. I don't use autolayout because it was too difficult to adjust it will all components of the cell which may be there or not. I manually calculate each time the rectangles and that works.
In respect to the rotation, I have tried implementing in the table view controller the willRotateToInterfaceOrientation method with [self.tableView reloadData] inside. This generates the cells again after rotation. Fine.
Inside of the cell class, I invoke [self.barChart setNeedsDisplay] to ensure that the subviews of the chart will be reloaded, which works.
Now the problem. Initially, portrait view opens and loads correctly. When I rotate to landscape, that works as well. When I rotate back to portrait, the length of the bar is calculated correctly but still displayed as it was in landscape. So the new rectangle for the bar has the right measures but the bar is displayed too long and partly outside of the screen.
A label with the same measures for the frame is displayed (and centered) correctly, so it should be a problem of the bar view reloading.
What am I doing wrong?
Try checking the [[UIApplication sharedApplication] statusBarOrientation]
when reloading your tableview then adjust accordingly. That will give the current rotation status.
I just solved my problem. I found three major mistakes in my code.
1) I was using dequeueReusableCellWithIdentifier after removing controls from cells. This resulted in missing controls and strange behavior. Now I generate each time a new cell from the nib.
2) I was using x and y values of controls which I had removed from the cell. I just put the numeric values instead.
3) I was using the frame for determining the width of the screen. However, the frame does not change. To solve this, I used the following thread: How to get orientation-dependent height and width of the screen?
Now, I don't even need the line [self.barChart setNeedsDisplay] and I can rotate the device as much as I want, the controls don't shift anymore. :)
I am still not sure that I have to invoke reloadData for adjusting the layout but I haven't found a better solution.
So, finally it works! Thank you a lot for the help and I hope, this post will help someone else. :)

Strange black bars in UITableView

I'm really scratching my head over this one: When I make visible the Toolbar of the navcontroller in my view hierarchy, strange black bars appear at the top and bottom of the table view. http://grab.by/8pgz
The app is universal, and on the iPhone simulator (or device) this does not show up, although they use the same UITableViewController subclass.
I cannot even figure out what the extra bars are, which makes it even harder to come up with a solution.
They are, however, not navbar / toolbar. They are not section or table view header / footer. It does not merely seem to be a resizing of the table view either, since its background is not black.
The custom table view controller sits inside a UINavigationController, which in turn is inside a UISplitViewController. Pretty standard, as far as I understand.
Like said, they do not show up on the phone - nor do they appear in the popover in portrait orientation.
I'm really out of clues here. Any suggestions would be most welcome.
Cheers,
Gregor
Sweden
Update: Problem solved by moving the code for making toolbar visible to -(void)awakeFromNib method instead of -(void)viewDidLoad. Still don't know what went wrong, but now at least it works.
I believe there is a problem with the frame you're trying to use to initialize the tableView.
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, height, width);
Try changing the height width variables in code, to reflect your height & width on the iPad.

UITableViewController, getting bounds of visible area

I've got this question. In my app I have many cells. When user clicks on something I'm loading VC and pushing it. To indicate this behaviour I'm displaying a subview which informs that now application is loading. Problem is, when user scrolls down and taps on cell my subview still is on the top of the tableView thus user isn't seeing it.
I need to change frame of my subview so my user can see it. I want this frame to be the center of the current view. How I can do that?
Fore example: My content is 800 pixels worth of height, now I'm displaying at 400 pixels subview with specific information about loading. When my user scrolls down to a cell that is at 2400 pixels, I'm still displaying subview at 400 pixels and thus it is unviewable by user.
I was trying to calculate new frame.origin.y by checking y of a cell that is tapped. Problem is the cell at 2400 pixels could be the first cell user is seeing or the last one, so how I can get the middle of the screen?
Edited with some screens:
When I select first time:
When I select after scrolling down big time:
What it looks like you have done here is added the loading view as a subview to the UIScrollView. You need to add the loading viewController into the parentView after the scrollview.
If this cant be done because your viewController is a subclass of UIScrollview, change it to a regular UIViewController subclass but implement the scrollView protocols and then do as i have said above. Other than that you would have to map the frame of the loading ViewController to the offset on the scrollView-not a good idea.

iPhone: How can I turn a flipside view into a scrolling UIScroll view?

This should be simple.
I'm making a very basic app, based on the Utility Application template of XCode.
On the flipside, I have more content than fits the screen.
The flipside is a UIView. I think it should be a UIScrollView, but somehow I don't get it to work.
Can anybody here advise me on this?
With a UIScrollView it is not enough just to place the control into Interface Builder and place the items within it; you have to set its content size in code.
Therefore in the -viewWillAppear method (or similar) you should have something like:
[scrollView setContentSize:CGSizeMake(320, 600];
This would make the content size inside the scroll view 600 pixels high (ie larger than the height of your iPhone display). If everything else is wired up correctly, this shoud now work.
Note: You may also then need to reposition your objects within the view. Set frame.origin for the objects that require this...

Resizing UITableView on RootController

Is it possible to resize the UITableView on the RootController of a nav based app? When RootViewController.xib is opened in IB, there isn't a view. Just the UITableView. Clicking the inspector and then the little yellow ruler, frame height is grayed out. I'm adding a toolbar programmatically to the RootViewController:
[toolbar setFrame:rectArea];
That works fine but the bottom cell in the tableview is partially hidden because the tableview doesn't know about the toolbar.
The easiest way, is to adjust the contentInset (which is inherited from UIScrollView). Resizing by setting the frame can cause crazy drawing bugs in cells.
For example, if you are trying to resize a tableview for the keyboard, do something like this:
tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, 216.0, 0.0);
tableView.scrollIndicatorInsets = tableView.contentInset;
Hope that helps someone. This way worked best for me.
Yes, but you need to have a ViewController (not a UITableViewController) as the root controller for the nav, and wrap the actual UITableView in the UIViewControllers view.
You can still have the UIViewController conform to the UITableViewDelgate and Datasource protocols, and use all the same methods you have now in your UITableViewController.
P.S. you'll get more responses if you use the plain "iphone" tag.
You could also just set the Content and Scroller inset of the tableview
I encountered a similar issue when attempting to display the detail controller by itself, see: http://vimeo.com/13054813
The issue is that the SplitView controller applies its own transform to the sub-controllers, taking them out of the orientation detection loop, which blows goats and seems incredibly 'hackish' for built-in classes. (The video illustrates what happens when you make the detail view the root view, then add it back to the split view and make the split view root while in landscape; you get double rotation of the detail view.)
Unfortunately I've again run into these transformation issues while attempting to resize a SplitViewController's detail sub-view in response to the keyboard appearing/disappearing. In portrait, all works fine, in landscape it's fscked.
Yes, adjust the contentInset and scrollIndicatorInsets are the convenient way to resize the UITableView.
As the answer of Sam Soffes posted, I succeed resize UITableView in UITableViewController for the bottom UIToolbar.