Scroll Doesn't work Help would be graet - ios

I have tried this code but scrollview is not working.
Please help
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
scrollView.showsVerticalScrollIndicator=YES;
CGRect contentRect = CGRectZero;
for (UIView *view in scrollView.subviews) {
contentRect = CGRectUnion(contentRect, view.frame);
}
scrollView.contentSize = contentRect.size;
//scrollView.contentSize=CGSizeMake(self.view.bounds.size.width,tableView.bounds.size.height+100);
[self.view addSubview:scrollView];
UITableView *tableView=[[UiTableView alloc]initWithFrame:CGRectMake(0,200, self.view.bounds.size.width, self.view.bounds.size.height)];
tableView.dataSource=self;
tableView.delegate=self;
//tableView.keepOneSectionOpen = YES;
//tableView.initialOpenSections = [NSSet setWithObjects:#(0), nil];
tableView.scrollEnabled = NO;
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewCellReuseIdentifier];
[tableView registerNib:[UINib nibWithNibName:#"AccordionHeaderView" bundle:nil] forHeaderFooterViewReuseIdentifier:kAccordionHeaderViewReuseIdentifier];
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,200)];
imageView.image=[UIImage imageNamed:#"download (1).jpeg"];
imageView.userInteractionEnabled=YES;
imageView.alpha=1;
[scrollView addSubview:imageView];
[scrollView addSubview:tableView];

UITableView is a subclass of UIScrollView, not a subview, so you should just use the table view directly.
For more information read this explanation

I think the way you did is not correct. If you want to add an image above table view, try using tableHeaderView.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
self.tableView.tableHeaderView = imageView;

Related

UITableView over scroll to bottom but top is normal

added in viewDidLoad
navgationBar.translucent =N0, iOS 10.3, xcode 8.3
- (void)__setUpUI{
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)];
[tableView registerNib:[UINib nibWithNibName:#"DXGroupMasterLikesCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NSStringFromClass([DXGroupMasterLikesCell class])];
_tableView = tableView;
_tableView.backgroundColor = [UIColor orangeColor];
tableView.delegate = self;
tableView.dataSource = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableView];}
like this
but if I set [self.view addSubview:[UIView new]]; before [self.view addSubview:tableView]; everything is ok
somebody know why ?

UIImageView not showing on iOS6

in ios5 i implemented my UIImageView like this:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"FirstScreen.png"]];
imageView.frame = CGRectMake(0.0,0.0,[GeneralUtils screenWidth],[GeneralUtils screenHeight]);
// !!!!!!!!!!!!!
[self.view addSubview: imageView];
[self.view sendSubviewToBack:imageView];
[self.view sendSubviewToBack:self.tableView];
Everything´s fine...But now in ios6 my UIImageView is not showing anymore....
try bellow code..
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"FirstScreen.png"]];
imageView.frame = screenBounds;
[self.view addSubview:imageView];
[self.view bringSubviewToFront:self.tableView];
[self.tableView setBackgroundColor:[UIColor clearColor]];
Solved it by setting
[self.tableView setBackgroundView: nil];
I think my tableView was hiding the Image!

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 - Autoresizing for UITableView

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.

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