I have a button in headerview of my tableview, its woking fine as well, but problem i am having is: When I want to hide that button on click of another button. How can I achieve this? I have already tried
[deletebutton removeFromSuperview];
where deleteButton is my buttons name.
Here is what I am doing
-(void)PutTableinEditMode{
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom];
DeleteButton.frame=CGRectMake(10,1, 65, 25);
[DeleteButton setTitle:#"Delete" forState:UIControlStateNormal];
DeleteButton.backgroundColor=[UIColor clearColor];
[DeleteButton addTarget:self action:#selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:DeleteButton];
}
Then I m having another function as below from where i want to hide this DeleteButton
-(void)DoneEditing
{
DeleteButton.hidden=YES;
[DeleteButton removeFromSuperview];
}
deletebutton.hidden = YES
if any of those two solution (removeFromSuperview and hidden) do not work, then you certainly don't have the right reference to your button. I guess your using nib files to define your views ? Then be sure the member deleteButton is well "linked" to the actual button. (i.e. verify using debug that your deleteButton var is not null)
Can u try and change the Text of that button because i'm thinking your sending messages to nil objects.
I got the it working actually [DeleteButton removeFromSuperView] is working .. problem was that the first method PutTableinEditMode was being called from somewhere else also, so i simply took a bool variable and on basis of its value added and removed the delete button
:)
Thanks guys for helping though :)
Ifeel so stupid to make such a silly mistake :)
Related
I have a tableview that contains a row with a custom cell that contains a UIButton. However, the button doesn't always fire the action. Here's my code:
submitButton = [[UIButton alloc] init];
[[submitButton layer] setBorderColor:[[UIColor whiteColor] CGColor]];
[submitButton setClipsToBounds: YES];
submitButton.backgroundColor = [UIColor grayColor];
[submitButton setTitle:#"Send" forState:UIControlStateNormal];
[self.contentView addSubview:submitButton];
[submitButton addTarget:self action:#selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[submitButton release];
This is called in the custom cell's -(id)initWithStyle:
The buttonAction method looks like this:
-(void)buttonAction
{
NSLog(#"Button Clicked!");
}
It seems that the only way I can get the buttonAction to fire is if I press down on the button and release somewhere inside the cell's frame, but not inside the button itself. Why would that be?
*UPDATE*
Problem still exists, but I found that the more consistent way to get the button to fire is to click and drag to the left or right and then let go, as long as I let go within the bounds of the cell/row.
UPDATE #2
It looks like if I use iOS 6.0, it works as intended. But on 5.0 or 5.1 it does not.
Try assigning the same method call to TouchUpOutside as well - you should then see it work every time. TouchUpInside is only fired if you lift your finger while still within the bounds of the button.
Try [submitButton sizeToFit]. I'm wondering whether your button has any size (since I don't see you giving it any).
Also: Create your button with [UIButton buttonWithType: UIButtonTypeCustom] instead of alloc-init.
I am using tableView .
Now I want to make a button in my last cell??
can anyone tell me how to do this??
other data I am getting by an array . I want to add the button after the last element of the table
Is there any specific reason to display the button when user scroll till end of the last row of the table,
if yes:
then you can add your button in tableFooterView
else :
you can reduce the height of your table view in such a way so you can
add a custom view contains your button and place your custom view
after your tableView
Add your button as a tableFooterView of the table, this is much simpler than trying to use a custom cell for the last row.
i am not having my mac right now trying to guide you:
1.Implement CellForRowAtIndexPath method.
2.u can use something like
`if (indexpath.row==[array count])
{
//make button here with cgrectmake and add to the view
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect/custom/...];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[cell addSubview:button ];
}`
hope it help you
I'm trying to add subviews to a UIButton. This is working fine right now. But the button isn't clickable anymore as soon as I add the subviews.
I use the following code:
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*100+24, row*80+10, 64, 64);
[button addSubview:asyncImage];
[button addSubview:price];
[button addTarget:self
action:#selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
The button works again if I remove the 2 addSubview: methods. If anyone knows how to fix this it would be great!
I found a quick solutions. I needed to set the asyncImageView to the following:
asyncImage.userInteractionEnabled = NO;
asyncImage.exclusiveTouch = NO;
After this, it worked!
try:
[UIButton buttonWithType:UIButtonTypeCustom];
instead of:
[UIButton buttonWithType:UIButtonControlType];
The important thing here is to make sure that userInteractionEnabled will be set to NO. Fortunately it works immediately for UIImageView and UILabel (maybe for other subclasses of a UIView but those are the most popular subviews added to button) because by default for this classes it is set to NO by default. Unfortunately it is set to YES in UIView so make sure to change it in that case. Messing around with any other flags shouldn't be necessary. The nature of problem is that many people do not know that default value of this flag is different in subclasses.
Have you tried to put:
[asyncImage setUserInteractionEnabled:YES];
in the same sitiation i make this action:
inherit from UIButton and add all labels and imageview's of button to self, finally put new button to view as last subview and add targets of self button to this last button(also set backgroundColor to clearColor for transparent). now it will be clickable and works fine.
In Swift, test that is you have your UIButton blocked
uibtn.userInteractionEnabled = false
uibtn.exclusiveTouch = false
I added a label to the subview button.
For a very long time I was looking for why my text in the button is not clickable. Solution in this thread:
myLable.isUserInteractionEnabled = false
I receive some JSON from the net and based on that data, I must create 2 or 3 buttons. Part of my gui is static and created in NIB (won't change), only the number of buttons will change. I found this code for making buttons in code:
//create the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//set the position of the button
button.frame = CGRectMake(100, 170, 100, 30);
//set the button's title
[button setTitle:#"Click Me!" forState:UIControlStateNormal];
Is this the right way? In which method of my viewcontroller should I put this code?
You can add the button whenever you want, as long as the view has been loaded already. The one thing you'd need to add to the above code is
[[self view] addSubview:button];
Using this code, you have a button on the screen, but it won't be able to trigger any actions. You'll probably also want to add:
[button addTarget:self action:#selector(someMethod:) forControlState:UIControlEventTouchUpInside];
You should add the buttons in the delegate/method that parses the JSON data.
Don't forget to add the created buttons to your view:
[containerView addSubview:button];
In my application, i have some leftBarbutton of the navigation bar set to " retour" and some others set to "back" i would like to set all my buttons to "retour", how to do this please ? i have spend many hours to dos this.
thanks
I reckon you want to change the language, rather than the button description itsself.
In oder to change the language have a look into the (appname)-Info.plist.
There is an Attribute: Localization native development region.
Change it accordingly to, i guess in your case France if. am not horribl wrong.
Cheers,
Sebastian
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:#"retour" forState:UIControlStateNormal];
btn.frame=CGRectMake(3, 2, 53, 30);
UIBarButtonItem *btnBack=[[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem=btnBack;
[btnBack release];
[btn release];