UIView Animation Block Not Doing Anything - objective-c

I have a very small animation I want to do by moving a view's frame using blocks (rather than the animation headers).
My view hierarchy is quite big so I will explain everything in regards of the specific view I want to animate.
The biggest view is the one that takes the whole screen, so it is 320x480 points. Inside this view, I have another view called "keypadContainerView" that is 320x200 points, located on 0, 261 and it appears at the bottom of the screen. This keypadContainerView has a subview called keypadView, which has a bunch of small buttons as subviews.
Biggest View -> KeypadContainerView -> keypadView -> UIbuttons.
An screenshot:
Although this could go without saying, the keypad there is the keypadContainerView, with is't keypadView and buttons. I need this hierarchy because I'm aiming for eye candy here, and each layer has a different background.
The way I create and deal with that view is here:
keypadViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 261, 320, 200)] autorelease]; //(Original is 0, 261, 320, 200)
keypadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[keypadViewContainer addSubview:keypadView];
//Add the buttons
[self.view addSubview:keypadViewContainer];
And this is how I'm trying to animate it:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIView animateWithDuration:5.0 animations:^{
self.keypadViewContainer.frame = CGRectMake(0, 0, 320, 200);
} completion:NULL];
}
What is funny is that if I NSLog something in the animations: parameter, I actually get some output so the method is definitely getting called. It's just not animating anything at all.
The whole controller code is here, in case you need it:
//UnlockKeyboardViewController
//------------------------------------------------------------------------
#interface UnlockKeyboardViewController : UIViewController
{
NSArray *buttons;
NSArray *passcodeFields;
UIImage *buttonBackgroundImage;
UIImage *buttonBackgroundHighlightedImage;
UIImage *middleButtonBackgroundImage;
UIImage *middleButtonBackgroundImageHighlighted;
UIImage *screenBackgroundImage;
UIImage *infoViewContainerImage;
UIImage *keypadViewContainerImage;
UIImage *passcodeFieldsContainerImage;
UIImage *infoViewImage;
UIImage *passcodeViewImage;
UIView *infoViewContainer;
UIView *keypadViewContainer;
UIView *passcodeFieldsContainer;
UIView *infoView;
UIView *keypadView;
UIView *passcodeFieldsView;
UIView *infoToDisplayView; //The view the programmer passes to show in infoView.
}
#property(nonatomic, retain)UIImage *buttonBackgroundImage;
#property(nonatomic, retain)UIImage *buttonBackgroundHighlightedImage;
#property(nonatomic, retain)UIImage *screenBackgroundImage;
#property(nonatomic, retain)UIImage *keypadViewBackgroundImage;
#property(nonatomic, retain)UIImage *infoViewContainerImage;
#property(nonatomic, retain)UIImage *keypadViewContainerImage;
#property(nonatomic, retain)UIImage *passcodeFieldsContainerImage;
#property(nonatomic, retain)UIImage *infoViewImage;
#property(nonatomic, retain)UIImage *passcodeViewImage;
#property(nonatomic, retain)UIView *infoToDisplayView;
//Properties for container views.
#property(nonatomic, retain)UIView *infoViewContainer;
#property(nonatomic, retain)UIView *keypadViewContainer;
#property(nonatomic, retain)UIView *passcodeFieldsContainer;
#end
#implementation UnlockKeyboardViewController
#synthesize buttonBackgroundImage = _buttonBackgroundImage;
#synthesize buttonBackgroundHighlightedImage = _buttonBackgroundHighlightedImage;
#synthesize screenBackgroundImage = _screenBackgroundImage;
#synthesize keypadViewBackgroundImage = _keypadViewBackgroundImage;
#synthesize infoViewContainerImage = _infoViewContainerImage;
#synthesize keypadViewContainerImage = _keypadViewContainerImage;
#synthesize passcodeFieldsContainerImage = _passcodeFieldsContainerImage;
#synthesize infoViewImage = _infoViewImage;
#synthesize passcodeViewImage = _passcodeViewImage;
#synthesize infoToDisplayView = _infoToDisplayView;
//Synthesizers for container views.
#synthesize infoViewContainer = _infoViewContainer;
#synthesize keypadViewContainer = _keypadViewContainer;
#synthesize passcodeFieldsContainer = _passcodeFieldsContainer;
-(void)loadView
{
[super loadView];
self.view.frame = CGRectMake(0, 0, 320, 480);
_unlockKeyboardBundle = [NSBundle bundleForClass:[self class]];
buttonBackgroundImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"button" ofType:#"png"]];
middleButtonBackgroundImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"middleButton" ofType:#"png"]];
buttonBackgroundHighlightedImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"pushedButton" ofType:#"png"]];
middleButtonBackgroundImageHighlighted = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"pushedButtonMiddle" ofType:#"png"]];
infoViewContainerImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"infoViewContainerImage" ofType:#"png"]];
keypadViewContainerImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"keypadViewContainerImage" ofType:#"png"]];
passcodeFieldsContainerImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"passcodeViewContainerImage" ofType:#"png"]];
infoViewImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"infobackground" ofType:#"png"]];
passcodeViewImage = [UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"passcodescreen" ofType:#"png"]];
//self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[_unlockKeyboardBundle pathForResource:#"lockbackground" ofType:#"png"]]];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
keypadViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 261, 320, 200)] autorelease]; //(Original is 0, 261, 320, 200)
keypadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[keypadViewContainer addSubview:keypadView];
keypadViewContainer.backgroundColor = [UIColor colorWithPatternImage:keypadViewContainerImage];
NSMutableArray *tempButtons = [NSMutableArray array];
self.view.opaque = YES;
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setTitle:#"1" forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 0, 106, 50);
UIButton *button4 = [UIButton buttonWithType:UIButtonTypeCustom];
[button4 setTitle:#"4" forState:UIControlStateNormal];
button4.frame = CGRectMake(0, 50, 106, 50);
UIButton *button7 = [UIButton buttonWithType:UIButtonTypeCustom];
[button7 setTitle:#"7" forState:UIControlStateNormal];
button7.frame = CGRectMake(0, 100, 106, 50);
UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
[cancel setTitle:NSLocalizedString(#"cancel", #"Cancel string") forState:UIControlStateNormal];
cancel.frame = CGRectMake(0, 150, 106, 50);
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setTitle:#"2" forState:UIControlStateNormal];
button2.frame = CGRectMake(106, 0, 108, 50);
UIButton *button5 = [UIButton buttonWithType:UIButtonTypeCustom];
[button5 setTitle:#"5" forState:UIControlStateNormal];
button5.frame = CGRectMake(106, 50, 108, 50);
UIButton *button8 = [UIButton buttonWithType:UIButtonTypeCustom];
[button8 setTitle:#"8" forState:UIControlStateNormal];
button8.frame = CGRectMake(106, 100, 108, 50);
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setTitle:#"0" forState:UIControlStateNormal];
button0.frame = CGRectMake(106, 150, 108, 50);
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
[button3 setTitle:#"3" forState:UIControlStateNormal];
button3.frame = CGRectMake(214, 0, 106, 50);
UIButton *button6 = [UIButton buttonWithType:UIButtonTypeCustom];
[button6 setTitle:#"6" forState:UIControlStateNormal];
button6.frame = CGRectMake(214, 50, 106, 50);
UIButton *button9 = [UIButton buttonWithType:UIButtonTypeCustom];
[button9 setTitle:#"9" forState:UIControlStateNormal];
button9.frame = CGRectMake(214, 100, 106, 50);
UIButton *cancelOrDelete = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelOrDelete setTitle:#"<-" forState:UIControlStateNormal];
cancelOrDelete.frame = CGRectMake(214, 150, 108, 50);
[tempButtons addObject:button1];
[tempButtons addObject:button2];
[tempButtons addObject:button3];
[tempButtons addObject:button4];
[tempButtons addObject:button5];
[tempButtons addObject:button6];
[tempButtons addObject:button7];
[tempButtons addObject:button8];
[tempButtons addObject:button9];
[tempButtons addObject:button0];
[tempButtons addObject:cancel];
[tempButtons addObject:cancelOrDelete];
buttons = [[NSArray arrayWithArray:tempButtons] retain];
for(UIButton *theButton in buttons)
{
if([theButton.currentTitle isEqualToString:#"2"] || [theButton.currentTitle isEqualToString:#"5"] || [theButton.currentTitle isEqualToString:#"8"] || [theButton.currentTitle isEqualToString:#"0"])
{
[theButton setBackgroundImage:middleButtonBackgroundImage forState:UIControlStateNormal];
[theButton setBackgroundImage:middleButtonBackgroundImageHighlighted forState:UIControlStateHighlighted];
}else
{
[theButton setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal];
[theButton setBackgroundImage:middleButtonBackgroundImageHighlighted forState:UIControlStateHighlighted];
}
[keypadView addSubview:theButton];
}
[self.view addSubview:keypadViewContainer];
passcodeFieldsView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 110)] autorelease];
passcodeFieldsContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 151, 320, 110)] autorelease];
passcodeFieldsContainer.backgroundColor = [UIColor colorWithPatternImage:passcodeFieldsContainerImage];
passcodeFieldsView.backgroundColor = [UIColor colorWithPatternImage:passcodeViewImage];
NSMutableArray *passTemps = [NSMutableArray array];
UITextField *tf1 = [[[UITextField alloc] initWithFrame:CGRectMake(24, 27, 50, 50)] autorelease];
UITextField *tf2 = [[[UITextField alloc] initWithFrame:CGRectMake(98, 27, 50, 50)] autorelease];
UITextField *tf3 = [[[UITextField alloc] initWithFrame:CGRectMake(172, 27, 50, 50)] autorelease];
UITextField *tf4 = [[[UITextField alloc] initWithFrame:CGRectMake(246, 27, 50, 50)] autorelease];
[passTemps addObject:tf1];
[passTemps addObject:tf2];
[passTemps addObject:tf3];
[passTemps addObject:tf4];
passcodeFields = [[NSArray arrayWithArray:passTemps] retain];
for(UITextField *theTf in passcodeFields)
{
theTf.borderStyle = UITextBorderStyleBezel;
theTf.backgroundColor = [UIColor whiteColor];
theTf.enabled = NO;
theTf.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
theTf.textAlignment = UITextAlignmentCenter;
theTf.adjustsFontSizeToFitWidth = YES;
theTf.alpha = 0.7;
theTf.secureTextEntry = YES;
[passcodeFieldsView addSubview:theTf];
}
[passcodeFieldsContainer addSubview:passcodeFieldsView];
[self.view addSubview:passcodeFieldsContainer];
infoView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 151)] autorelease];
infoView.backgroundColor = [UIColor colorWithPatternImage:infoViewImage];
infoViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 151)] autorelease];
infoViewContainer.backgroundColor = [UIColor colorWithPatternImage:infoViewContainerImage];
[infoViewContainer addSubview:infoView];
[self.view addSubview:infoViewContainer];
[pool drain];
}
-(void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIView animateWithDuration:5.0 animations:^{
self.keypadViewContainer.frame = CGRectMake(0, 0, 320, 200);
} completion:NULL];
}
-(void)dealloc
{
[buttons release];
[passcodeFields release];
[buttonBackgroundImage release];
[buttonBackgroundHighlightedImage release];
[screenBackgroundImage release];
[infoView release];
[keypadView release];
[passcodeFieldsView release];
[infoViewContainerImage release];
[keypadViewContainerImage release];
[passcodeFieldsContainerImage release];
[infoViewImage release];
[passcodeViewImage release];
[infoToDisplayView release];
[super dealloc];
}
#end
I have a small feeling it may have something to do with the way I'm dealing with my views, so there's the whole source code.
Any help with this will be highly appreciated.

Instead of those :
keypadViewContainer = [[[UIView alloc] initWithFrame:CGRectMake(0, 261, 320, 200)] autorelease];
Use
Self.keypadViewContainer = .....
and your #synthesize are wrong.
You declare iVars explicitly without underscore,
But use synthesize to create underscored iVars.
So your properties correspond to
_keypadViewContainer
but in your loadView you assign to keypadViewController
Quickest fix: just use #synthesize instead of synthesize = ...
(that is only if you don't use Xcode 4.4!)
Best fix: get rid of the explicit iVar declaration and
Make sure to use _keypadViewContainer etc. when you access iVar directly like in dealloc.
Ideal fix: use ARC and use IB to build your keypad interface (why don't you btw?)

Related

Calling a method inside a delegate

I am using zBar SDK once a qr code detected a delegate will run, inside this delegate I defined a myView and used it as a overlay on the camera with information about that qr code.
inside the myView there is a button which calls a method (testAction) but inside this method I cannot acces any of objects which I'd defined in the delegate, how can I access to to myView and objects inside that inside testAction?
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
UIView *myView;
CGRect frame= CGRectMake(0, 0, 320, 428);
myView=[[UIView alloc] initWithFrame:frame];
myView.backgroundColor=[UIColor greenColor];
myView.alpha=0.7;
CGRect labelFrame = CGRectMake( 0, 0, 500, 30 );
UILabel* myLabel = [[UILabel alloc] initWithFrame: labelFrame];
[myLabel setTextColor: [UIColor orangeColor]];
NSString *combined = [NSString stringWithFormat:#"%#%#", #"Title: ", symbol.data];
myLabel.text=combined;
UIButton * myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(10, 50, 100, 50);
myButton.tag = 121;
[myButton setTitle:#"Do Something" forState:UIControlStateNormal];
[myButton setBackgroundImage:nil forState:UIControlStateNormal];
[myButton addTarget:self action:#selector(testAction:) forControlEvents:UIControlEventTouchUpInside];
//[button setBackgroundColor:red];
[myView addSubview: myLabel];
[myView addSubview: myButton];
reader.cameraOverlayView=myView;
}
- (void)testAction: (id)sender{
//my issue is here
}
Make them properties.
In your interface have:
#property (strong, nonatomic) UIView *myView;
#property (strong, nonatomic) UILabel *myLabel;
#property (strong, nonatomic) UIButton *myButton;
In your delegate method:
CGRect frame= CGRectMake(0, 0, 320, 428);
self.myView=[[UIView alloc] initWithFrame:frame];
self.myView.backgroundColor=[UIColor greenColor];
self.myView.alpha=0.7;
CGRect labelFrame = CGRectMake( 0, 0, 500, 30 );
self.myLabel = [[UILabel alloc] initWithFrame: labelFrame];
self.myLabel.textColor = [UIColor orangeColor];
self.myLabel.text = [NSString stringWithFormat:#"%#%#", #"Title: ", symbol.data];
self.myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.myButton.frame = CGRectMake(10, 50, 100, 50);
self.myButton.tag = 121;
[self.myButton setTitle:#"Do Something" forState:UIControlStateNormal];
[self.myButton setBackgroundImage:nil forState:UIControlStateNormal];
[self.myButton addTarget:self action:#selector(testAction:) forControlEvents:UIControlEventTouchUpInside];
[self.myView addSubview:self.myLabel];
[self.myView addSubview:self.myButton];
reader.cameraOverlayView = self.myView;
Finally in your action:
- (void)testAction: (id)sender
{
// self.myView, self.myLabel and self.myButton are all available.
}

textfield for ios

i am very new to iOS and xcode. i want to create a textfield without using nib files or storyboard. i searched for the answers but everywhere its kind of confusing or they have used nib files. i have created buttons and its working fine but for textfields m facing problems. here is my viewcontroller.m please help.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view.backgroundColor = [UIColor purpleColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UITextField *textfield;
button.frame = CGRectMake(10 ,350 , 300, 40);
button1.frame = CGRectMake(10 ,50 , 300, 40);
textfield.frame = CGRectMake(10, 100, 200, 30);
[button setTitle:#"Change screen to green!" forState:UIControlStateNormal];
[button1 setTitle:#"click screen to red!" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self action:#selector(buttonPressed1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[self.view addSubview:button1];
[self.view addSubview:textfield];
}
-(void)buttonPressed {
self.view.backgroundColor = [UIColor greenColor];
}
-(void)buttonPressed1 {
self.view.backgroundColor = [UIColor redColor];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
thanks & regards
You just declared the UITextField instead of allocating. You must allocate it first then set frame & add it on the view like -
UITextField *txt = [[UITextField alloc] init];
txt.frame = CGRectMake(10, 100, 200, 30);
txt.delegate = self;
[self.view adsubview:txt];
It solves your problem.
First use
UITextField *textfield = [[UITextField alloc] init];
instead of
UITextField *textfield;
Then set backgroud color of textfield since the backgroud color will be clearColor by default.
textfield.backgroundColor = [UIColor whiteColor];
or use
textfield.borderStyle = UITextBorderStyleRoundedRect;
to get white colored bordered text field.
If you've added the alloc init like the answers have suggested, your text field is in fact on the screen, but since it has no border or no text, you can't see it. Try adding this line, and then you will see it:
textfield.borderStyle = UITextBorderStyleRoundedRect;
Use this:
UITextField *textfield = [[UITextField alloc] init];
Insetd of
UITextField *textfield;
UITextField *textfield; Just crete object reference Not object.
UITextField *textfield =[[UITextField alloc] init];
textfield.frame = CGRectMake(10, 100, 200, 30);
textfield.delegate = self; [self.view addSubview:textfield];
[self.view bringSubViewToFront:textfield];
may solve the problem

How to add a custom view programmatically on a custom cell?

I have a question that is perhaps very basic.
I`m building a custom cell, without a Xib file, all programmatically. In my CustomHell.m file I have basically only two methods: initWithStyle and layoutSubviews.
I have managed to add programmatically some labels and a button. Now I wish to add a specific custom view - FacebookLikeView (https://github.com/brow/FacebookLikeView) - but I have no idea how to do it.
This is the code in my "initWithStyle:reuseIdentifier:
//StoreName Label
storeName = [[UILabel alloc] init];
storeName.textAlignment = UITextAlignmentLeft;
storeName.font = [UIFont boldSystemFontOfSize: 16]; //12
storeName.backgroundColor = [UIColor clearColor];
storeName.adjustsFontSizeToFitWidth = YES;
//checkIn Button
checkInButton = [UIButton buttonWithType:UIButtonTypeCustom];
checkInButton.frame = CGRectMake(203,10,86,25);
[checkInButton setImage:[UIImage imageNamed:#"Check-In.png"] forState:UIControlStateNormal];
[checkInButton addTarget:self.nextResponder action:#selector(addCheckin:) forControlEvents:UIControlEventTouchUpInside];
checkInButton.backgroundColor = [UIColor redColor];
//FACEBOOK
facebookLikeButton = [UIButton buttonWithType:UIButtonTypeCustom];
facebookLikeButton.frame = CGRectMake(169,40,119,25);
[self.contentView addSubview:storeName];
[self.contentView addSubview:storeAddress];
[self.contentView addSubview:subtitle];
[self.contentView addSubview:checkInButton];
[self.contentView addSubview:facebookLikeButton];
//[self.contentView addSubview:likeButton];
return self;
And this is my layoutSubviews:
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
storeName.frame = CGRectMake(boundsX+10, 15, 190, 20);
storeAddress.frame = CGRectMake(boundsX+10, 42, 200, 40);
subtitle.frame = CGRectMake(boundsX+10, 77, 280, 30);
likeButton.frame = CGRectMake(boundsX+199, 42, 50, 20);
The header file looks like this:
#import "FacebookLikeView.h"
#interface CustomCellHead : UITableViewCell
{
FacebookLikeView *likeButton;
UIButton *facebookLikeButton;
UIButton *checkInButton;
UILabel *storeName;
UILabel *storeAddress;
UILabel *subtitle;
}
#property(nonatomic,retain) FacebookLikeView *likeButton;
#property(nonatomic,retain) UIButton *checkInButton;
#property(nonatomic,retain) UILabel *storeName;
#property(nonatomic,retain) UILabel *storeAddress;
#property(nonatomic,retain) UILabel *subtitle;
#end
Try [self addSubview: storeName] instead of [self.contentView addSubview: storeName]

Changing value on a label with UISlider control in WePopoverControler

I am in a process of implementing WePopovercontroller in my app and I have a question on how to implement uislider on it. I am able to show the slider in the UIView and get the action when slider moved but not sure how to set the value of the label in that view. Here is the part of the code
-(void)popoverSliderMoved:(UISlider *) sender{
NSLog(#"slider %f",sender.value);
}
-(IBAction)showSettingsMenu:(UIButton *)sender{
if(!self.popoverSettingsController) {
// Create a label and button for the popover
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
[label setText:#"Bookmark it!"];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:UITextAlignmentCenter];
UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 45, 100, 40)];
[slider addTarget:self action:#selector(popoverSliderMoved:) forControlEvents:UIControlEventValueChanged];
UIFont *font = [UIFont boldSystemFontOfSize:20];
[label setFont:font];
CGSize size = [label.text sizeWithFont:font];
CGRect frame = CGRectMake(0, 0, size.width + 10, size.height + 10); // add a bit of a border around the text
label.frame = frame;
UIButton *button = [[UIButton alloc] initWithFrame:label.frame];
[button addSubview:label];
[button addTarget:self action:#selector(popoverButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIViewController *viewCon = [[UIViewController alloc] init];
[viewCon.view addSubview:slider];
[viewCon.view addSubview:button];
CGRect popOverFrm = CGRectMake(0, 0, frame.size.width + slider.frame.size.width, frame.size.height + slider.frame.size.height);
viewCon.contentSizeForViewInPopover = popOverFrm.size;//CGSizeMake(100, 36);
NSLog(#"Label Frame: %#", NSStringFromCGRect(label.frame));
NSLog(#"Popover size: %#", NSStringFromCGSize(viewCon.contentSizeForViewInPopover));
NSLog(#"ViewCon: %#", NSStringFromCGRect(viewCon.view.frame));
self.popoverSettingsController = [[WEPopoverController alloc] initWithContentViewController:viewCon];
//[self.popoverSettingsController setDelegate:self];
}
if([self.popoverSettingsController isPopoverVisible]) {
[self.popoverSettingsController dismissPopoverAnimated:YES];
// [navPopover setDelegate:nil];
self.popoverSettingsController = nil;
} else {
[self.popoverSettingsController presentPopoverFromRect:CGRectMake(sender.frame.size.width, 0, 200, 57)
inView:self.navigationController.view
permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown
animated:YES];
}
}
Would i need to use a delegate in this case or a property for this viewcontroller to set the label.
Thanks!!!
Yes using a property would be what I would do.

Custom TabBar with UIButtons

First: Sorry for my bad English!
I have a class in which I create UIButton. The UIButton I add a UIView. In the ViewController I would like to add these custom tabbar. This works well so far. However, there are problems with addTarget: action: forControlEvents: - How can I run from the ViewController an instance method in the class? The class is of type NSObject. My code:
TabBar *tabBar = [[TabBar alloc] init];
[tabBar tabBarButton];
[tabBar.home addTarget:tabBar action:#selector(switchView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tabBar.tabView];
And here is my Class:
#implementation TabBar
#synthesize tabView, home, list, charts, favorits, more;
-(void)tabBarButton{
tabView = [[UIView alloc] initWithFrame:CGRectMake(0, 360, 320,56)];
home = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 43, 56)];
list = [[UIButton alloc] initWithFrame:CGRectMake(63, 0, 40, 56)];
charts = [[UIButton alloc] initWithFrame:CGRectMake(123, 0, 49, 56)];
favorits = [[UIButton alloc] initWithFrame:CGRectMake(192, 0, 66, 56)];
more = [[UIButton alloc] initWithFrame:CGRectMake(278, 0, 42, 56)];
[home setImage:[UIImage imageNamed:#"home.png"] forState:UIControlStateNormal];
[list setImage:[UIImage imageNamed:#"liste.png"] forState:UIControlStateNormal];
[charts setImage:[UIImage imageNamed:#"charts.png"] forState:UIControlStateNormal];
[favorits setImage:[UIImage imageNamed:#"favorites.png"] forState:UIControlStateNormal];
[more setImage:[UIImage imageNamed:#"more.png"] forState:UIControlStateNormal];
home.tag = 1;
list.tag = 2;
charts.tag = 3;
favorits.tag = 4;
more.tag = 5;
[tabView addSubview:home];
[tabView addSubview:list];
[tabView addSubview:charts];
[tabView addSubview:favorits];
[tabView addSubview:more];
}
-(void)switchView{
NSLog(#"hi");
}
When I start the app, it crashes immediately when I press one button.
If you're getting an unrecognized selector error, you might try:
[tabBar.home addTarget:tabBar action:#selector(switchView:) forControlEvents:UIControlEventTouchUpInside];
Note the colon behind action:#selector(switchView:)