iPad - Autoresizing for UITableView - ios

My Code is Here :
CGRect mainFrame = [UIScreen mainScreen].bounds;
_contentView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0.0, mainFrame.size.width, mainFrame.size.height-20)] autorelease];
_contentView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
_contentView.backgroundColor = [UIColor clearColor];
[self.view addSubview:_contentView];
self.tableView = [[[UITableView alloc] initWithFrame:_contentView.frame style:UITableViewStylePlain] autorelease];
[self.tableView setBackgroundColor:[UIColor clearColor]];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[self.tableView setSeparatorColor:[UIColor clearColor]];
[_contentView addSubview:_tableView];
self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
I add a tableview on _contentView and _contentView on self.view
on iPhone works good without problem, but on iPad I don't know why when I set autoresizing mask for table view, it increases width and height... without autoresizing mask works good, but I need autoresizing mask for landscape. How to solve this ?
with autoresizing mask
without autoresizing mask

Once try this
_contentView.autoresizesSubviews = YES ;
Hope this will work.

Related

uitableviewcell get offset after set navigationBarHidden = YES and and a custom bar view

THE BUG PICTURE
This picture is the bug picture,and my code is as follow:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
naviview = [[UIImageView alloc] init];
naviview.backgroundColor = [UIColor colorWithHexString:#"fcfcfc"];
naviview.frame = CGRectMake(0, 0, VIEW_BOUNDS.width, 64);
[self.view addSubview:naviview];
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, VIEW_BOUNDS.width, self.view.bounds.size.height-62-TABBARHEIGHT) style:UITableViewStylePlain];
self.tableView.showsHorizontalScrollIndicator = NO;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = [UIColor grayColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view insertSubview:_tableView belowSubview:self.naviview];
}
if I use [self.view insertSubview:_tableView belowSubview:self.naviview]; the cell have a offset, buf if i use [self.view addSubview:_tableView] the cell will be right. I want to know the reason lead to the offset,someone can tell me?
Thanks a lot!
Because when you use addSubview then it is getting added on superview and the and frame of tableview will be calculated with view's frame. But in insertSubView is getting added behind navView. There might be possibility that tableView frame is getting calculated with different frame.
You can verify it by making tableView frame height 0 and then try using insertSubView.

UscrollView: bad scroll on iPhone 6 plus

I have a problem. I use a UIScrollView with 1 image and 2 tableview inside.
The scroll works correctly on an iPhone 5 but on an iPhone 6Plus the scroll has a problem not so easy to explain. If I tap in light way the scroll is ok, but if I tap in a little long way the screen the scroll doesn't works. Here the code that I used.
self.scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
self.scrollView.scrollEnabled = YES;
self.scrollView.delegate = self;
[self addSubview:self.scrollView];
self.theImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, lenghtImage, hightImage)];
self.theImage.image = [UIImage imageNamed:#"theImage.png"];
[self.scrollView addSubview:self.theImage];
self.tableA = [[UITableView alloc] initWithFrame:CGRectMake(0, yPosA, self.bounds.size.width, heightA];
self.tableA.delegate = self;
self.tableA.dataSource = self;
self.tableA.scrollEnabled = NO;
[self.scrollView addSubview:self.tableA];
self.tableB = [[UITableView alloc] initWithFrame:CGRectMake(0, yPosB, self.bounds.size.width, hightB)];
self.tableB.delegate = self;
self.tableB.dataSource = self;
self.tableB.scrollEnabled = NO;
[self.scrollView addSubview:self.tableB];
self.scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, heightA + heightB);
can your tableviews be eating the touches? have you tried with tableView.userInteractionEnabled = false to see if it works ?

UIView Programmatic Width Constraint

What kind of constraint(s) do I need to add in order to ensure when the phone rotates the search bar and label span the width of the phone?
Below is code I am using to spin up a search bar & label and add them to a table header:
self.venueSearchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.venueSearchController.searchResultsUpdater = self;
self.venueSearchController.searchBar.delegate = self;
self.venueSearchController.delegate = self;
self.venueSearchController.dimsBackgroundDuringPresentation = NO;
self.venueSearchController.hidesNavigationBarDuringPresentation = YES;
self.venueSearchController.searchBar.frame = CGRectMake(0, 0, self.venueSearchController.view.frame.size.width, 44.0);
// create a UISegmentControl
UILabel *tableHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, self.venueSearchController.view.frame.size.width, 30)];
[tableHeaderLabel setTextAlignment:NSTextAlignmentCenter];
tableHeaderLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
tableHeaderLabel.text = #"Text Here";
tableHeaderLabel.backgroundColor = [UIColor redColor];
// create a custom UIView
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, 74)];
[myView addSubview:tableHeaderLabel]; // add header label
[myView addSubview:self.venueSearchController.searchBar]; // add search bar to custom view
self.tableView.tableHeaderView = myView;
FYI I fixed this by simply using autoresizingMask
tableHeaderLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
self.venueSearchController.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

Arrange UIscrollView to back

Maybe a huge noob question but i cant seem to figure it out, even after some time googling i cant find out to arrange a scrollview underneeth a navigation bar.
My code:
- (void)loadView {
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scroll.backgroundColor = [UIColor blackColor];
scroll.delegate = self;
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Plattegrond DeFabrique schematisch.png"]];
scroll.contentSize = image.frame.size;
[scroll addSubview:image];
scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
scroll.maximumZoomScale = 2.0;
[scroll setZoomScale:scroll.minimumZoomScale];
self.view = scroll;
}
Try inserting the view behind the superview or try sendSubviewToBack.
[[self.view superview] insertSubview:scroll belowSubview:self.view];
or
[self.view sendSubviewToBack:scroll];
It sounds like you are just wanting to add the scroll view to the self.view though. Do as the other answer suggest and create the scrollView from the self.view frame then add it to your self.view.
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame]; // Thilina
[self.view addSubview:scroll];
Since you are passing the frame of [UIScreen mainScreen] at the time of allocating the UIScrollView , the size of UIScrollView is overlapping the UINavigation . Replace it with
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
also rather than replacing the self.view with the scrollView , try to add the scrollView as subview on self.view
[self.view addSubview:scrollView];
Do the following task in the viewDidLoad
Hope it will help you.
You can simply use the self.view's frame when creating the ScrollView. This will solve your problem.
- (void)loadView {
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
scroll.backgroundColor = [UIColor blackColor];
scroll.delegate = self;
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Plattegrond DeFabrique schematisch.png"]];
scroll.contentSize = image.frame.size;
[scroll addSubview:image];
scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
scroll.maximumZoomScale = 2.0;
[scroll setZoomScale:scroll.minimumZoomScale];
[self.view addSubView:scroll]; //MarkM
}

Ipad tableview and imageview

How to insert four tableview in a scrollview by pagination.i know how to do this ,but i need a image view as first page and then tableview as second,third and forth page.
Thankz in advance
_scroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 55, 1000, 460)];
_scroll.backgroundColor=[UIColor clearColor];
_scroll.pagingEnabled=YES;
_scroll.contentSize = CGSizeMake(1000*5, 460);
[_scroll setBackgroundColor:[UIColor lightGrayColor]];
CGFloat x=0;
for(int i=1;i<6;i++)
{
UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(x+10, 10, 750, 440) style:UITableViewStylePlain];
[table setBackgroundColor:[UIColor whiteColor]];
table.rowHeight = 120;
table.separatorColor = [UIColor grayColor];
table.delegate=self;
//table.dataSource=self;
[_scroll addSubview:table];
[table release];
x+=1000;
}
[self.view addSubview:_scroll];
_scroll.showsHorizontalScrollIndicator=NO;
[_scroll release];
Ignoring the recommendation that UITableViews are not embedded inside scroll views as they are scrollviews in themself. So dont do this (not a joke).
You add the imageview with addSubview: just like the tableviews you want add. They are all UIViews and are all treated the same way.
So for a hypothetical scrollview with size (100,100) and imageview/tableviews of size (100,100)
imageview.frame = CGRectMake(0,0,100,100);
[scrollview addSubview:imageview];
tableview1.frame = CGRectMake(100,0,100,100);
[scrollview addSubview:tableview1];
tableview2.frame = CGRectMake(200,0,100,100);
[scrollview addSubview:tableview2];
tableview3.frame = CGRectMake(300,0,100,100);
[scrollview addSubview:tableview3];
scrollview.contentSize = CGSizeMake(400,100);
scrollview.pagingEnabled = YES;

Resources