I want to create a tableView or tabs that expands when user selects them. This is very commonly used in webpages using jquery.
you can check http://jqueryui.com/accordion/ It does exactly what i want to do in my ipad app. with horizontal tabs too http://jqueryui.com/tabs/
Can anyone tell me how to achieve this in my iPad app ? Or any pointers would be appreciated.
TIA
Sam
1.Use UITableView for first type of tab.
a) Use Header and Cell View in your desired format.
b) Hide and unhide cell view with some animation.
2.Use UISegementedControl for second type of tab.
a) Use function addTarget :
[self.mySegmentedControl addTarget:self action:#selector(segmentChanged) forControlEvents:UIControlEventValueChanged];
b) Implement segmentChanged :
- (void) segmentChanged:(UISegmentedControl *)paramSender{
//check if its the same control that triggered the change event
if ([paramSender isEqual:self.mySegmentedControl]){
//get index position for the selected control
NSInteger selectedIndex = [paramSender selectedSegmentIndex];
if (selectedIndex == 1 ) { // do required } and so on....
}
}
The best possible way is using the headerview to show the Master row and the tableview cells for showing the Details row.Write a touch event for the headerview and set it with the showing and hiding the cells ,with neat row animation.You need to keep the status of the opened and closed state of cell with an array of bools repesenting the no of masterview.
Related
I want to set a recent search history dropdown for UISearchbar . I have implemented a dropdown programatically using a UITableView
Logic:
How i have implemented is by setting a UITableView right below the UISearchBar and on click on the UISearchBar it will pop up .
Am initially hiding that tableview in viewdidload and in
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar am unhiding the tableview .
Iam facing too many problems with this :
1. The return button is not enabled when the searchbartext is empty .In that case if i have to cancel/hide the table view again i have to depend on tapgestures .
2. Clicking on the searchbartext again won't trigger any of its delegates. The only time it triggers the delegates on click on the searchbartext is when click on it for the first time then it calls -(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
Do u guys have any other solution / way to implement this feature in a much better way than this ??
Do we have any custom made UISearchBar recent history dropdowns ??
I have searched for a custom UISearchBar recent history dropdown in cocoacontrols,code4app and cocoapods for this no hope dint find any .
Please help me with this .
For your first issue, you can add a category on UISearchBar something like this and this shall always enable your return button on keyboard when tapped on UISearchBar
#implementation UISearchBar (MyAddition)
- (void)alwaysEnableSearch {
// Loop around subviews of UISearchBar
NSMutableSet *viewsToCheck = [NSMutableSet setWithArray:[self subviews]];
while ([viewsToCheck count] > 0) {
UIView *searchBarSubview = [viewsToCheck anyObject];
[viewsToCheck addObjectsFromArray:searchBarSubview.subviews];
[viewsToCheck removeObject:searchBarSubview];
if ([searchBarSubview conformsToProtocol:#protocol(UITextInputTraits)]) {
#try {
// Force return key to be enabled
[(UITextField *)searchBarSubview setEnablesReturnKeyAutomatically:NO];
}
#catch (NSException *iException) {
}
}
}
}
For second issue, why don't you use shouldChangeTextInRange: delegate method which gets called for each entered character.
As a side note, this SO thread has a sample code to do this. This may help you.
Good luck!
I am re-writing the possible steps as per your recent clarification.
keep a flag/boolean to monitor tableview is hidden or not.
in the UISearchBar Delegate method check the serachbar's text field's [obj isFirstResponder] method.
a. if firstResponder =yes --> Show the histroy tableview OR Vice versa.After show/hide is accomplished call below method on UISearchBar' textfield.
*[searchbarobj.textfield resignFirstResponder];*
b. if firstResponder = No---> Don't do anything. leave the method.
I am using https://github.com/CEWendel/SWTableViewCell library to my project.
Certain situation I need to disable the particular button action of swipe cell.
I cannot find any property in their class file. If anyone crossed this, give me answer.
Here I have attaced my swipe options image:
For ex
: I want to disable the share button action.
Let's assume your share button is in the leftButtonsArray. In the method:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:(SWCellState)state
{
//case:left buttons opened
UIButton *shareButton = leftButtonsArray[theIndexOfTheShareButton];
shareButton.enabled = NO;
}
#karthikeyan You can hide the button for a particular row in tableview by the following code:
- (void)updateRightUtilityButtons:(NSArray *)rightUtilityButtons WithButtonWidth:(CGFloat) width {
_rightUtilityButtons = rightUtilityButtons;
[self.rightUtilityButtonsView updateUtilityButtons:rightUtilityButtons WithButtonWidth:width];
[self.rightUtilityButtonsView layoutIfNeeded];
[self layoutIfNeeded];
}
Add/update this methods to SWTableViewCell.m class, where rightUtilityButtons is an array of buttons you need to display for the particular row.
In case if you want to disable just user interaction you can achieve while adding button into array, just disable user interaction for that button by shareButton.userInteration = NO and then add to array and then pass the array to the method defined above. By this you can be sure that button is disabled.
But please provide the sample code that you have worked so that can update your code directly.
In case if you still didn't get revert back I'll give you the working code directly here.
I have a UITableView with a custom UITableCellView subclass. I want to show one of the rows as active or selected. The controls in my cell have their own gestures, but I have area on the right where I can do the selection. I had (naively) thought I could just indicate I wanted a checkmark style accessory but Apple's docs say
This control does not track touches. The delegate of the table view
can manage check marks in a section of rows (possibly limiting the
check mark to one row of the section) in its
tableView:didSelectRowAtIndexPath: method.
I'm not sure how to interpret that, but I put the tableView:didSelectRowAtIndexPath: method in my delegate, and it never fires. Regardless of where I touch my cell (on the part where there are touchable controls or not). So I'm curious why that doesn't work? I also noticed that regardless of how I set the selected property on the cells, the checkmark always shows on, so I don't think it's really meant to be used a selection indicator.
But I'm actually kind of OK with that. I don't really want a checkmark, I'd rather do something like mail does when it does multi select on the left side, the radio-button-esque style circles. Which then leads me to a quandary about how to proceed. Should I just add a button control to the right side, manipulate the images appropriately in my custom cell subclass? Do I mess with the background image of the button in that case? Or just the image? And since selecting one needs to deselect the others, what's the best way to connect this to the table view delegate, rather than the subclass? Or should I make a custom NSView subclass?
UPDATE
I removed the accessory. I added an UIImageView to show selection state. Because the sub control in my cell uses a hold gesture, the selection tap makes it through just about everywhere for the cell. I synchronize the visual selection state using the following method:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
self.selectionView.image = self.selected ? [UIImage imageNamed: #"selected"] : [UIImage imageNamed: #"not_selected"];
}
To my custom controller, I added the following method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[Site setCurrent: self.allSites[indexPath.row]];
[[Site current] pullValves];
}
It finally donned on me that that the first method was for updating the visual state, but not for responding to the users intent, that belongs in the second method. The first fires at various times, but the second applies when the user actually does the tap.
Finally, I had to programmatically set
self.clearsSelectionOnViewWillAppear= NO;
Not matter what I set in the storyboard, that value was YES, so returning to the list was clearing my selection.
You're adding a gesture to each of the cells you create? I would back that out of there and create a gesture on the main controller which holds your tableview (not the individual cells).
Add this to your main controller so the controller can handle the gestures accordingly.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
If you need to track the cell that was touched (say, for a panning gesture), you can grab the index path given the gesture recognizer.
CGPoint p = [recognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
From there, we go back to your goal: tracking your active cell. tableView:didSelectRowAtIndexPath needs to be hit (hopefully the steps above help here). Store some sort of identifier of the item you need to keep selected. When tableView:willDisplayCell:forRowAtIndexPath is called you can trigger the selection state.
I want to have a UISegmentedControl with a number of selectable options in it, but also include an Info button, which is not selectable. The UISegmentedControl class reference talks about using a momentary disclosure button, hinting that its possible, but there is nothing else there or in the header file that explains how to do such a thing.
So how can I do this?
After much experimentation, I found that keeping a shadow variable on the selected index let me do this. In the following code, the info button is 1, the other buttons are selectable. In viewDidLoad set the initial value (or ask the control for its selected index). Then use the following code for the action method:
- (IBAction)segmentAction:(UISegmentedControl *)sender
{
NSUInteger idx = [sender selectedSegmentIndex];
switch(idx) {
case 1: // momentary button
sender.selectedSegmentIndex = selectedIndex;
break;
default:
selectedIndex = idx;
// other stuff
break;
}
...
Essentially all you need to do is reset the selected index. Tested with iOS7 only.
I'm preparing a UITableView with a custom prototype cell having a UISwitch widget on the right side, and I'd like to let my users be able to delete rows.
Everything is fine with that, except the fact that when the delete button shows up it overlaps to the UISwitch, this way:
Is it possible to have the UISwitch shifting left when the delete button appears?
Epilogue
I've decided for brevity to not shift my UISwitch position when "delete" button appears, but to make it disappear, bringing it back when the "delete" button is gone.
So, according to #geo suggestion (thank you), I've managed it out (quite simply) this way:
In my UITableViewCell' subclass .m file:
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if (state & UITableViewCellStateShowingDeleteConfirmationMask) {
activationSwitch.hidden = YES;
}
else {
activationSwitch.hidden = NO;
}
}
I hit a very similar problem and fixed it. You need the right autoresizing mask (assuming not doing auto layout here) for your UI elements in your custom tableview cell in Interface Builder.
In my case, I needed to add the Left constraint (see that little autoresizing picture/animation in the Size Inspector, View section) for each of my UI elements.
Add a Left "bar", and you should be good.
Override the Methode
-(void)willTransitionToState:(UITableViewCellStateMask)state
-> UITableViewCellStateShowingDeleteConfirmationMask
of your custom Cell and do there your customizing :)