I have a table view (filled by customs cells) and my idea is have a tabbar button (such as "edit button"). Pressing on it, in all row, the button cancell will appear. Is it possible?
You can create the code for the button (you know... UIButton* button = [UIButton alloc]init];) in your cell and set it to Hidden = YES, then add a BOOL to check if the "edit button" was pressed, lets name it BOOL editActive, then when the button is pressed you will check the editActive, if its NO then the Hidden value of the button will be NO and you reload your table with [yourTableView reloadData], otherwise, if editActive = YES, then you must hide your "Cancel button" in the cell and once again use [yourTableView reloadData]
Related
On Select a table row when the button is clicked in the row. I have cells that contains a button in each row. My problem is when I click on a button in a row the row does not get selected.How do I make the row get selected when I click a button in that row? Uisnd Xamarin IOS
You need to add addTarget for your button in cellforrowAtIndexpath method like this
[cell.yourbutton addTarget:self action:#selector(buttonclick:) forControlEvents:UIControlEventTouchUpInside];
-(void)buttonclick:(UIButton*)sender
{
// get your button action here..
}
I am using MGSwipeTableCell in my app. When a cell is swiped open to reveal buttons if I tap on another cell it dismisses the swipe cell (hides the buttons again). I want the previously swiped cell to dismiss the buttons and then select the new cell in one tap instead of two (i.e. tap off and then tap new cell). Is there any way to to do this?
See the description below, I think this delegate function of MGSwipeTableCell might help you.
-(void) swipeTableCell:(MGSwipeTableCell*) cell didChangeSwipeState:(MGSwipeState) state gestureIsActive:(BOOL) gestureIsActive
{
/**
* Called when the user clicks a swipe button or when a expandable button is automatically triggered
* #return YES to autohide the current swipe buttons
**/
}
On MGSwipeTableCell version 1.5.4 or later
cell.touchOnDismissSwipe = YES;
It will dismiss the cell you did swiped and also select the cell you tap
I want to have a function that by pressing the 1st button, then the 2nd button will be appear. When the 2nd button appear, after pressing it, then the 3rd button will appear and so on until the 10th button.
Making IBAction for each button can do the job. But it will be very time consuming. And I have multiple of these sequence needed to be done.
Is there any other way is faster and simpler to get this job done?
Thanks
For this purpose, you have to use the tag property of UIButton. while creating the UIButton set the tag value. For example for button1 it should be 1, for button2 it should be 2, and so on...
After that set the same IBAction for all UIButtons. And inside that IBAction get the button based on tag value and unhide next UIButton.
-(IBAction)buttonClicked:(id)sender
{
UIButton *button = (UIButton *)[self.view viewWithTag:(sender.tag + 1)];
button.hidden = NO;
}
You should be use loop for these process . . .
(if second button not appear only on first button click)
I have a ViewController called NotepadView.h/.m with a UIButton that has the title "User: (Select)". Once the user touches the button, a UIPickerView appears as a popover, which is initialized from UserPickerViewController.h/.m. Once the button is clicked, the proper rows appear in the picker. But after an IBAction is implemented (tapping the button, choosing the correct row form the picker, then leaving the picker) the button title only updates after the button is pressed again.
I know this is because I am using a touch up inside action, so once the button is touched, the title is immediately changed to "User: (null)" until it is touched a second time after the proper row has been selected in the picker. How do I implement an action so that when the picker row is selected, it immediately changes the button title, instead of filling it with "User: (null)" until i touch it again?
Also, how would I go about exiting the UserPickerViewController.m after the row is selected, and segueing back to the NotepadView.m besides touching outside of the picker view?
NotepadView.m under viewDidLoad:
[_userBTN setTitle: #"User: (Select)" forState: UIControlStateNormal];
Under an IBAction of touch up inside:
- (IBAction)refreshUsername:(id)sender {
[_userBTN setTitle: [NSString stringWithFormat:#"User: %#",gUserInfo.chosenUserName] forState: UIControlStateNormal];
}
In UserPickerViewController.m:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSArray *userArray = [gUserInfo availableUsers];
gUserInfo.chosenUserName = [userArray objectAtIndex:row];
}
As #JasonMcDermott recommended, I changed my UserPickerViewController.m to contain a UIBarButton called "Save". Once the button is pressed, using an unwindSegue, the string from the picker row, is stored in a variable named user, which is then transferred over to the NotepadView.m upon touchUpInside.
I have a simple TableView containing several cells. Normally, I switch to selected cell details by tapping this cell. But what if I need a dedicated button for every cell? I've seen "Table View Cell" properties in Interface Builder, it has what I need, but it can't be added to existing cells.
How to properly add this kind of button to every cell of standard TableView?
I do something similar in an app I am working on right now. I have a cell that has a button on it, and I need to know which button was pushed in which cell. I do that like this..
I add my button to each cell..
// add buy button to each cell
UIImage *image;
buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
image = [UIImage imageNamed:#"buy.png"];
[buyButton setBackgroundImage:image forState:UIControlStateNormal];
buyButton.frame = CGRectMake(220, 35, 96, 34);
[buyButton setTag:cellIndex];
[buyButton addTarget:self action:#selector(buyTickets:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:buyButton];
The method used to determine which "button" in which cell was selected, I then push another view controller with the information of the selected button...
// buy tickets button pressed from main table view
- (void) buyTickets:(id)sender{
ResultViewController *vc = [[ResultViewController alloc] init];
vc.buyMovieID = [sender tag]; // "sender tag" is the cell id the button is located in
[[super navigationController] pushViewController:vc animated:YES];
[vc release];
}
This is what the button looks like on each cell.
Hope this helps!
P.S. Tapping on the CELL, would push another view controller, but tapping on "Buy Tickets" button pushes a different one.
alt text http://luistovar.com/ultratableview.jpg
I think the detail disclosure accessory type is what you need. The doc can be found on UITableViewCell class reference.
It says :
The accessory view appears in the the right side of the cell in the table view’s normal (default) state. The standard accessory views include the disclosure chevron; for a description of valid accessoryType constants, see “Cell Accessory Type.” The default is UITableViewCellAccessoryNone. If a custom accessory view is set through the accessoryView property, the value of this property is ignored. If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends the data-source object a tableView:accessoryButtonTappedForRowWithIndexPath: message.
Setting your cell's accessoryType property to UITableViewCellAccessoryDetailDisclosureButton, you can easily do whatever you wan when the detail disclosure button is pressed. What's great about using this accessory type is that it's a standard button, so it is user-friendly and it does all the job of tracking which cell has been touched for you.
If you want to use a custom button, you should set the accessoryView property to that custom button and listen to events on it.
The way i added a button to a tableview cell was by subclassing UITableViewCell and then building its view in interface builder.