hi i am having text view and on it one button to move to main view ,but i am using this is not working for me..
BackButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
BackButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[BackButton addTarget:self action:#selector(Back) forControlEvents:UIControlEventTouchUpInside];
[BackButton setBackgroundColor:[UIColor blackColor]];
and my method for back is
-(void) back{
what should i place here to current view to dismiss.........
}
Try
[self removeFromSuperview];
Related
I don't know why I am getting this problem.
Details - I have a tab-bar controller in my application. On one tab I have a form which contains some buttons. I am setting up the titles of these buttons. Now, when I change tabs and come back to the same tab, all the button titles appear darken.
I am attaching screen-shots as well.
Any help would be appreciated.
Thank you !!
EDIT : Here is the code of how I am creating the buttons -
-(void)viewWillAppear:(BOOL)animated
{
float yFrame =310.0f;
for(int i =0;i<7;i++){
openPickerButton=[UIButton buttonWithType:UIButtonTypeCustom];
openPickerButton.frame = CGRectMake(29.0, yFrame+10.0, 280.0, 48.0);
openPickerButton.tag=i;
openPickerButton.backgroundColor=[UIColor clearColor];
[openPickerButton setTitle:[formButtonTitle objectAtIndex:openPickerButton.tag] forState:UIControlStateNormal];
openPickerButton.titleLabel.font=[UIFont fontWithName:#"Helvetica" size:16];
[openPickerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
openPickerButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
openPickerButton.showsTouchWhenHighlighted = YES;
[openPickerButton addTarget:self action:#selector(PickChoreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[setPreferencesFormScrollView addSubview:openPickerButton];
yFrame+=60.0f;
}
}
Well in viewDidLoad your objects get called once.(As soon as the view get loaded.
Stop)
In viewWillAppear they get called every time the view appears.
- (void)viewDidLoad
{
[super viewDidLoad];
float yFrame =310.0f;
for(int i =0;i<7;i++){
openPickerButton=[UIButton buttonWithType:UIButtonTypeCustom];
openPickerButton.frame = CGRectMake(29.0, yFrame+10.0, 280.0, 48.0);
openPickerButton.tag=i;
openPickerButton.backgroundColor=[UIColor clearColor];
[openPickerButton setTitle:[formButtonTitle objectAtIndex:openPickerButton.tag] forState:UIControlStateNormal];
openPickerButton.titleLabel.font=[UIFont fontWithName:#"Helvetica" size:16];
[openPickerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
openPickerButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
openPickerButton.showsTouchWhenHighlighted = YES;
[openPickerButton addTarget:self action:#selector(PickChoreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[setPreferencesFormScrollView addSubview:openPickerButton];
yFrame+=60.0f;
}
}
Instead of creating buttons in viewWillAppear method create buttons in viewDidLoad method
I have this code that changes the back button of my UINavigationBar
// Set the custom back button
UIImage *buttonImage = [UIImage imageNamed:#"backag.png"];
//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"selback.png"] forState:UIControlStateHighlighted];
button.adjustsImageWhenDisabled = NO;
//set the frame of the button to the size of the image (see note below)
button.frame = CGRectMake(0, 0, 30, 30);
[button addTarget:self action:#selector(back) forControlEvents:UIControlEventTouchUpInside];
//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem;
// Cleanup
[customBarItem release];
If I put it in the viewDidLoad method it works fine. However, when I load the next view the old style button shows up. To fix this I tried putting this code in the next view's viewDidLoad method, but then no button is visible.
Any ideas as to what might be causing this?
Thanks!
Apply same code in
-(void)viewDidAppear:(BOOL)animated
{
}
I used tis code in both view and it's worked fine...
// add following code in your both view's viewDidLoad method...
UIButton *leftButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButton1 setImage:[UIImage imageNamed:#"Viewone.png"] forState:UIControlStateNormal];
leftButton1.frame = CGRectMake(0, 0, 30, 30);
[leftButton1 addTarget:self action:#selector(yourclickevent) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton1];
[leftButton1 release];
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButton setImage:[UIImage imageNamed:#"ViewSecond.png"] forState:UIControlStateNormal];
leftButton.frame = CGRectMake(0, 0, 30, 30);
[leftButton addTarget:self action:#selector(yourclickevent) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
[leftButton release];
Hope,this will help you...enjoy..
You need to ensure you set the hidesBackButton property on the navigationItem:
// Setup custom back button
self.navigationItem.hidesBackButton = YES;
I have added multiple actions to one button
Play audiofile
Display array of views
Button is playing audiofile but not displaying views.
UIButton *playpauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playpauseButton addTarget:self action:#selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
[playpauseButton addTarget:self action:#selector(displayviewsAction:) forControlEvents:UIControlEventTouchUpInside];
playpauseButton.frame = CGRectMake(0, 0, 50, 50);
[playpauseButton setImage:[UIImage imageNamed:#"play.png"] forState:UIControlStateNormal];
[playpauseButton setImage:[UIImage imageNamed:#"pause.png"] forState:UIControlStateSelected];
UIBarButtonItem *playpause = [[UIBarButtonItem alloc] initWithCustomView:playpauseButton];
Play Pause Action coding
-(void)playpauseAction:(id)sender
{
if
([audioPlayer isPlaying]){
[sender setImage:[UIImage imageNamed:#"play.png"] forState:UIControlStateNormal];
[audioPlayer pause];
} else {
[sender setImage:[UIImage imageNamed:#"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
}
}
DisplayviewsAction coding
- (void)displayviewsAction:(id)sender
{
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 30.0, 30.0);
self.pageViewController.view.frame = pageViewRect;
// Configure the page view controller
UIPageViewController *pageViewController = [[[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]autorelease];
NSArray *viewControllers = [NSArray arrayWithObject:pageViewController];
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self.view addSubview:self.pageViewController.view];
}
Any advice what i m missing in the code or doing wrong.
Thanks for help.
Here are some minor corrections you should make - they may not all help with the problem, but you never know.
Add a completion block here:
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
I don't remember for sure, but I think setViewControllers is done asynchronously - nothing cannot be added until after the completion handler is done. To add the block, you simply put a ^ and a block of code in (like a normal method):
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:^{
// your code here.
}];
This may fix the problem, but I cannot be sure until I can get back to my computer.
You should also put an NSLog at the beginning of every method, at least until you are done debugging. That way, you always know what is being called and what isn't. If it is not called, try removing the autorelease from the pageViewController - it may be released because it isn't being used.
I think the issue is in displayviewsAction, try something more simple like:
- (void) displayviewsAction:(id)sender
{
UIView* testView = [[UIView alloc] initWithFrame:CGRectInset(self.view.bounds, 30.0, 30.0)];
testView.backgroundColor = [UIColor greenColor];
[self.view addSubview:testView];
[testView release];
}
That should help you narrow down the problem. Depending on what your final aim is you might not need all those view controllers; instead consider UIView's transitionFromView... for the animation effects.
I have the following code:
self.shareButton=[[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 35, 35)];
[shareButton setBackgroundColor:[UIColor blueColor]];
[shareButton setBackgroundImage:[UIImage imageNamed:#"share_button"] forState:UIControlStateNormal];
[shareButton setBackgroundImage:[UIImage imageNamed:#"share_button_pressed"] forState:UIControlStateHighlighted];
[shareButton addTarget:self action:#selector(shareButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationController setToolbarItems:[NSArray arrayWithObject:shareButton] animated:YES];
Why I cannot see toolbar buttons? What's the problem?
What meggar says is probably the right answer. Try doing it this way.
--UPDATE--
Since the problem still exists I have updated the example to move the set call to the view controller instead of the navigation controller.
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
[self setToolbarItems:[NSArray arrayWithObject:barButtonItem] animated:YES];
[barButtonItem release];
I created a custom navigation back button. But when I add this code, my back animation doesn't work and it goes back with animation. Why? I think it depends on my #selector action.
- (void)viewDidLoad {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"goback.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(//HERE ! i don't know put what thing !) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 32, 32)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}
ok i created a function and works fine :D :
-(void)pushNav {
[self.navigationController popViewControllerAnimated:YES];
}