how to add button in the last cell of table? - iphone

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

Related

How to avoid the checkbox from being overlapped by the text in UITableView

I am able to add a checkbox to the UITableView but the checkbox is partially hidden by the text in the UITableView. Can anyone tell me how to align the two in the cell as the checkbox is hidden by the text.
This is the code for adding the checkbox.
UIButton *checkBox=[UIButton buttonWithType:UIButtonTypeCustom];
checkBox.tag=indexPath.row;
checkBox.frame=CGRectMake(2,12, 15, 15);
[cell.contentView addSubview:checkBox];
[checkBox setImage:[UIImage imageNamed:#"checkbox.png"] forState:UIControlStateNormal];
[checkBox addTarget:self action:#selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside];
Instead of using the cell's built-in label (or labels, depending on type), create your own label and add it as subview of the cell. This way, the custom label won't be autoresized or otherwise manipulated by the cell, potentially undoing your settings.
Try changing the cell.textLabel.frame to move it right by 15 points (and reduce it's width by 15 points too). Something like this:
cell.textLabel.frame.origin.x += 15;
cell.textLabel.frame.size.width -= 15;

UIButton tags in iPhone

I have 2 button objects (UIButton *obtn,*ebtn), I have created 12 buttons(6 buttons with 6 tag values for obtn, 6 buttons with 6 tag values for ebtn)... I have a single btnClick: method for all those 12 buttons... when i click on a button of tag value 1... Iam getting the properties of selected button to another button by using sender... I want to get the properties of unselected button (Example obtn object with tag value 3) into another button How can i get it...?
My Direct Question is: How to assign the properties of a button with a tag value to another button when it is in unselected state...
It sounds like you want to be able to get a pointer to a button with a certain tag, and at the moment all you can do is get the button that has sent you the action.
The method you are looking for is viewWithTag:. This will get you a button (or any other view) with the tag you want. You pass this method to the superview of the button. So, in your action method (assuming all buttons are in the same superview):
UIView *superview = [sender superview];
UIButton *otherButton = [superview viewWithTag:3];
You then have sender, which is the button that was tapped, and otherButton, which is the button with tag 3. You can modify each one as you wish.
// Create textfield 5
btn_select_Country = [UIButton buttonWithType:UIButtonTypeCustom];
//btn_select_Client = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn_select_Country.frame = CGRectMake(BTN_X_CORD, 228, BTN_WIDTH, BTN_HEIGHT);
btn_select_Country.tag = 1;
// [btn_select_Client setTitle:#"Button One" forState:UIControlStateNormal];
[btn_select_Country addTarget:self action:#selector(countryListBtnTap:) forControlEvents:UIControlEventTouchUpInside];
btn_Image_Select_Country= [UIImage imageNamed:#"drop-down.png"];
[btn_select_Country setImage:btn_Image_Select_Country forState:UIControlStateNormal];
//btn_select_Client.tag=1205;
[scrollview addSubview:btn_select_Country];
- (IBAction)currencyListBtnTap:(id)sender;
{
button_Number = [sender tag];
[self allTextFeildResignFirstResponder];
}

Multiple checkbox selection values to be displayed into the different cells of TableView

I have to select dynamically (random) check boxes which will be displayed into the previous list page below the cell values & for all cells it must be different as per the selection of those check boxes for the particular selected cells & when i will select particular cell from the list the listed check boxes should be selected in the list of the check boxes.
Is this possible? If possible then please tell me how.
This is what you want jignesh...
http://cocoawithlove.com/2009/01/multiple-row-selection-and-editing-in.html
best of luck
Yes it is possible you need to make an array of indexes and store indexes of the rows in which checkboxes are present.
What you need when you are making cells and add checkbox buttons then add index.row as its titleLabel.text. see this
UIButton *btn=(UIButton *)[cell viewWithTag:2];
if([self.indexArray containsObject:[NSString stringWithFormat:#"%i",indexPath.row]])
{
[btn setImage:[UIImage imageNamed:#"check.png"] forState:UIControlStateNormal];
}
else
[btn setImage:[UIImage imageNamed:#"uncheck.png"] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(changeButtonImage:) forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.text=[NSString stringWithFormat:#"%i",indexPath.row];
This code make your check box buttons and add its row no. with the button now you can access that button by this code.Also here i use an array index array which having indexes for checked rows.
Now see this function
-(void)changeButtonImage:(UIButton *)sender
{
if([self.indexArray containsObject:sender.titleLabel.text])
{
[sender setImage:[UIImage imageNamed:#"uncheck.png"] forState:UIControlStateNormal];
[self.indexArray removeObject:sender.titleLabel.text];
}
else
{
[sender setImage:[UIImage imageNamed:#"check.png"] forState:UIControlStateNormal];
[self.indexArray addObject:sender.titleLabel.text];
}
//other stuff
}
here simply add index and change button image to checked when indexarray not having that index otherwise remove that and set image unchecked.
Use this info with you logic and presence of mind.
Note:This is not exact answer but it shows a concept which you can use according to your situation.
It may be help full for you.

Where to insert code that creates buttons programmatically?

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];

how can i create array of buttons

hi i am new to iPhone.what i did is creating a 4 buttons individually.i need button tag values.when ever i check it in console i got 0 for 4 buttons,because i create 4 individual buttons .But i need buttons tag values like for first button, tag value 0,for second button, tag value 1.... like this how can i done this pls post some code.Thank u in advance.
for(int i=0;i<3;i++){
UIButton *theButton=[[UIButton alloc]init];
theButton.tag=i;
//set their selector using add selector
[theButton addTarget:self action:#selector(buttonClicked:)
forControlEvents:UIControlEventTouchDown];
//set their frame color title or image
}
-(void)buttonClicked:(UIButton *)inButton{
int tags=inbutton.tag;
}
You can specify the button tag like this :
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 setTag:1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button2 setTag:2];
By default the tag of the button is zero So if you have created four individual buttons the tag for all will be zero So What you can do is
If you have added four buttons from the xib file then set their tag as per your requirement in the xib file itself and give them same name
If you have taken the four buttons through code then set the tag through code
//Alloc buttonName1
buttonName1.tag=0;
//Alloc buttonName1
buttonName1.tag=1;
//Alloc buttonName1
buttonName1.tag=2;
//Alloc buttonName1
buttonName1.tag=3;
And for using it you have to go with pawans answer.
hAPPY cODING...