How to handle the touches event in subView - iphone

Here is my code:
mainView:
NSArray *btArray = [NSArray arrayWithObjects:#"1",#"1",#"1",#"1",#"1",nil];
ButtonBarComponent *bottomeButtonBar = [[ButtonBarComponent alloc] initButtonBarComponentWithButtonArray:btArray];
bottomeButtonBar.frame = CGRectMake(0, 340, 320, 200);
[self.view addSubview:bottomeButtonBar];
subView:
-(id)initButtonBarComponentWithButtonArray:(NSArray *)btArray {
self = [[UIView alloc] initWithFrame:CGRectMake(0, 340, 320, 200)];
self.backgroundColor = [UIColor whiteColor];
}
but why I cant run the code in touches event?

try setting user interaction enabled for your view and subview

Related

Programmatically add UILabel to toolbar

I am trying to add a UILabel programmatically into my UIToolBar but it dose not seem to be appearing. This is what I am doing with my code.
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:manufSelectionLabel];
matchingSeriesInfoToolBar.items = [NSArray arrayWithObject:textFieldItem];
manufSelectionLabel.text = #"Hello World!";
[super viewWillAppear:animated];
}
So pretty much I have created a custom toolbar which I have changed the usual location from the bottom of the screen, to appear under the UINavigationController, this is also added to the view like this so it animated properly in the view transitions..
After which I create the size of the tableview so that it appears after the custom toolbar..
then from there I am trying to add a UILabel to the toolbar.. but for some reason its not working out.
Any help would be greatly appreciated.
You must actually create the label somewhere. This code works just fine.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:toolbar];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
toolbar.items = [NSArray arrayWithObject:item];
label.text = #"Hello World";
In the code you posted you don't ever make a UILabel. Your comment says Ad UILabel to the toolbar but you then proceed to make a UIBarButtonItem with a custom view manufSectionLabel.
Where is the code which creates manufSectionLabel?
PS This line does nothing :
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
because at that point matchingSeriesInfoToolbar is nil - you haven't made it yet!

UITextView auto-complete bubble location

I am confused regarding auto-complete bubble location while entering data in UITextView.
What i have observed is that depending upon its frame's origin , auto-complete bubble either comes on top or bottom. There is no fixed location, provided scrollEnabled is set to NO.
Here are the two links. Code is written in init()
http://www.flickr.com/photos/26021742#N00/6975525835/
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 41)] autorelease];
view.backgroundColor = [UIColor grayColor];
[self.view addSubview:view];
UITextView *growingTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 200, 27)];
growingTextView.font = [UIFont fontWithName:#"Helvetica" size:13];
growingTextView.scrollEnabled = NO;
[view addSubview:growingTextView];
http://www.flickr.com/photos/26021742#N00/6975525727/
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 41)] autorelease];
view.backgroundColor = [UIColor grayColor];
[self.view addSubview:view];
UITextView *growingTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 200, 27)];
growingTextView.font = [UIFont fontWithName:#"Helvetica" size:13];
growingTextView.scrollEnabled = NO;
[view addSubview:growingTextView];
Can anyone explain this observed behavior ???
I know that popovers and bubbles will always automatically adjust it's position for ease of use. It's already on Apple's code and in both images the bubble position makes sense.

How to make UIScrollView stop immediately?

I just want to scroll only one page then to another.
I set m_pScrollView.pagingEnabled = YES and m_pScrollView.bounces = NO but when I scroll to the edge of the page it goes out of the page range and then back, likes an inertia effect.
I just want it scoll only one page not more. Can anyone help me?
- (void)viewDidLoad {
[super viewDidLoad];
m_pScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
m_pScrollView.delegate = self;
m_pScrollView.contentSize = CGSizeMake(768 * 3, 1024);
m_pScrollView.pagingEnabled = YES;
m_pScrollView.bounces = NO;
m_pScrollView.alwaysBounceHorizontal = NO;
m_pScrollView.alwaysBounceVertical = NO;
Myview *myview = [[Myview alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
myview.backgroundColor = [UIColor redColor];
Myview *myview2 = [[Myview alloc]initWithFrame:CGRectMake(768, 0, 768, 1024)];
myview2.backgroundColor = [UIColor blueColor];
Myview *myview3 = [[Myview alloc]initWithFrame:CGRectMake(768 * 2, 0, 768, 1024)];
myview3.backgroundColor = [UIColor grayColor];
[m_pScrollView addSubview:myview];
[m_pScrollView addSubview:myview2];
[m_pScrollView addSubview:myview3];
[self.view addSubview:m_pScrollView];
}
You have to set the content size like this
m_pScrollView.contentSize = CGSizeMake(x,y);
For more about this Create UIScrollview programmatically

iPhone SDK: UIScrollView does not scroll

I just can't get my scroll view to actually scroll.. Everything displays fine except it just won't scroll..... Here's my code:
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 600)];
scrollView.contentSize = CGSizeMake(320, 600);
scrollView.scrollEnabled = YES;
scrollView.clipsToBounds = YES;
[self.view addSubview:scrollView];
planView = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:#"WorkoutTable.png"]];
planView2 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:#"WorkoutTable.png"]];
planView2.frame = CGRectMake(0, 164, 320, 165);
planView3 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:#"WorkoutTable.png"]];
planView3.frame = CGRectMake(0, 328, 320, 165);
planView4 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:#"WorkoutTable.png"]];
planView4.frame = CGRectMake(0, 505, 320, 165);
[scrollView addSubview:planView];
[scrollView addSubview:planView2];
[scrollView addSubview:planView3];
[scrollView addSubview:planView4];
}
How do I fix this problem?
The contentSize must be larger than the scrollview's frame for there to be anything to scroll. :)
In this case, they're both (320, 600) so change your scrollView's init to
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
your scrollview frame should be smaller than contentSize,so only you can make scrollview scrollable.

UIScrollView: Scrolling doesn't work

I'd like to scroll my content in a UIScrollView. But I think I a made a mistake.
// setup view
CGRect appFrame = [UIScreen mainScreen].applicationFrame;
CGRect frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height);
self.view = [[[UIView alloc] initWithFrame:frame] autorelease];
// setup wrapper
UIScrollView *wrapper = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, appFrame.size.width, appFrame.size.height + 320)];
wrapper.backgroundColor = [UIColor redColor];
wrapper.scrollEnabled = YES;
[self.view addSubview:wrapper];
// title (simple version here)
title.text = "Hello World";
[wrapper addSubview:title];
Instead of setting large frame you must set UIScrollView's content size:
UIScrollView *wrapper = [[UIScrollView alloc] initWithFrame:
CGRectMake(0, 0, appFrame.size.width, appFrame.size.height)];
wrapper.contentSize =CGSizeMake(appFrame.size.width, appFrame.size.height + 320);