Scrollview paging within a tableview - objective-c

I want to create a scrollview with paging enabled,with 5 pages,but the problem is these page must hold tableview.how to do this.

Try this :
scroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scroll.backgroundColor=[UIColor clearColor];
scroll.pagingEnabled=YES;
scroll.contentSize = CGSizeMake(320*5, 460);
CGFloat x=0;
for(int i=1;i<6;i++)
{
UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(x+10, 10, 300, 440) style:UITableViewStyleGrouped];
table.delegate=self;
table.dataSource=self;
[scroll addSubview:table];
[table release];
x+=320;
}
[self.view addSubview:scroll];
scroll.showsHorizontalScrollIndicator=NO;
[scroll release];

Related

make non-move UITextField on background of UITableView

How to make UITextField on background of UITableView?
I want to set textField in the top and when i scroll tableView my textField don't move.
Something like this
- (void)viewDidLoad {
[super viewDidLoad];
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 30, 100, 30)];
self.textField.backgroundColor = [UIColor redColor];
self.tableView = [[UITableView alloc] initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];
self.tableView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);
[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:NSStringFromClass([TableViewCell class])];
[self.view addSubview:self.textField];
}
You have another solution - besides one suggested in comments:
You can create UIViewController with tableView and text field. Assign delegate and dataSource to the view controller. Pin text field to the top and you have your desired behaviour. You will have to connect tableView with IBOutlets.
If you want to set textField in the top change textField frame
From
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 300, 100, 30)];
To
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 30, 100, 30)];
self.textField.backgroundColor = [UIColor redColor];
[self.view addSubview:self.textField];
Also another solution is add textField to navigation item title.I tried this and it works fine.
textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 30, 100, 30)];
textField.backgroundColor = [UIColor redColor];
[self.view addSubview:textField];
self.navigationItem.titleView = self.textField;

White line on the bottom on ios 7 with UITextField

I have text field, i need to show the cursor and hide the keyboard. It looks ok in the IOS 6 and IOS 5. But in IOS 7 i can see small white line on the bottom.
My code is
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[scrollview setDelegate:self];
[self.view addSubview:scrollview];
[self.view bringSubviewToFront:scrollview];
[scrollview setBackgroundColor:[UIColor blackColor]];
scrollview.contentSize = CGSizeMake(768, 1024);
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 500, 100)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.returnKeyType = UIReturnKeyDone;
[textField setUserInteractionEnabled:YES];
[textField setEnabled:YES];
[scrollview addSubview:textField];
// Here I need to show the cursor without showing keyboard
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
((UITextField*)textField).inputView = dummyView;
[((UITextField*)textField) becomeFirstResponder];
Anyone having any thought how to fix this?
I think this is due to the keyboard view, whose having the height as 1.
So if you change the line
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
to
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
it will work.

Using subviews in scrollerview iPhone

I am trying to add uipickerview in uiscrollview, but it is not being shown properly, just a black square.
Further, I have to add 1 more uipickerview, some labels and some buttons.
The code I am using is as under:
-(void)loadView {
[super loadView];
UIPickerView *pView = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 280, 165)];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroller.pagingEnabled = YES;
NSInteger numberOfViews = 2;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.height;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
// awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroller addSubview:awesomeView];
[scroller addSubview:pView];
}
scroller.contentSize = CGSizeMake(self.view.frame.size.width , self.view.frame.size.height * numberOfViews);
[self.view addSubview:scroller];
}
what can be the issue?
Are you putting data in the picker view? I mean, if you just put the picker view without data on it you are not going to see anything on it.
You need to add the delegate and the datasource and put some data in your picker!
pView.delegate = self;
pView.datasource = self;
and then you have to implemente at least:
numberOfComponentsInPickerView:
numberOfRowsInComponent:
titleForRow:
make sure you are implementing uipickerviewdelegate methods. its normal that it will show just the black square because your pickerview cant find the data and thus does not display anything.
UIPickerView *pView = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 280, 165)];
Change height to 216 .. UIPickerView has fixed height of 216 ..only.. you can't change it..

How to programmatically add UIView in a scrollview in ios?

I used the below codes
CGRect scrollserviceViewFrame1 = CGRectMake(60,610, 650, 150);
//CGRect scrollViewFrame =[[UIScreen mainScreen] applicationFrame];
//UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
UIScrollView *servicescrollView1 = [[UIScrollView alloc] initWithFrame:scrollserviceViewFrame1];
[self.view addSubview:servicescrollView1];
//scrollView.backgroundColor=[UIColor greenColor];
[servicescrollView1 setBackgroundColor:[UIColor redColor]];
[servicescrollView1 setCanCancelContentTouches:NO];
//scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
servicescrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
servicescrollView1.scrollEnabled = YES;
servicescrollView1.autoresizesSubviews=YES;
[servicescrollView1 setContentSize: CGSizeMake(1050, 100)];
//scrollView.delegate = self;
servicescrollView1.pagingEnabled = YES;
servicescrollView1.showsHorizontalScrollIndicator = NO;
[servicescrollView1 scrollRectToVisible:CGRectMake(servicescrollView1.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
NSLog(#" scroll view width :%i ",servicescrollView1.frame.size.width);
NSLog(#"scroll view height :%i ",self.view.frame.size.height);
NSLog(#"self view width :%i",self.view.frame.size.width);
CGRect CGRectZero = CGRectMake(60,710,200, 100);
UIView* myserviceView1 = [[UIView alloc] initWithFrame: CGRectZero];
myserviceView1.backgroundColor=[UIColor blackColor];
[servicescrollView1 addSubview:myserviceView1];
[myserviceView1 release];
[servicescrollView1 release];
The scroll view is created , butcannot add the UIVIew to scrollview...
Any suggestions for solving this query???
Thanks in advance
Near the bottom of your code where you create myserviceView1, you (attempt to) reset a constant (CGRectZero).
And then when you create your myserviceView1 UIView, you're giving it a frame size of {0, 0, 0, 0}.

UIScrollView Help

Is there a way to put several UIViews In a UIScrollView in a tabbar page. If so, how would I do that? To make it simple, Imageine the homescreen icons on the springboard. Each page is a UIView. I want to basically put this on a tabbar page. Is this possible? How would I do it?
NOTE:
First try to accept the answers then only you will get lot of good answer from our seniors.....
first create the uiscrollview and then add that it to the tabbar... for creating the uiscrollview
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
[awesomeView release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];