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 :)
Related
In my app I have a UITableViewCell with a UITextField in it. When the user starts typing in this textfield, an autocomplete view appears.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (self.suggestions != nil) {
self.autocomplete = [[AutoComplete alloc] initWithFrame:CGRectMake(10, 53, self.frame.size.width-20, 200)];
self.autocomplete.delegate = self;
self.autocomplete.suggestions = self.suggestions;
[self addSubview:self.autocomplete];
[self bringSubviewToFront:self.autocomplete];
}
return YES;
}
This is nothing more than a UIView with a UITableView inside it. However, what happens is that this view is hidden behind the section header and the next cell.
So while it appears to be inserted above the cell, it registers the tapp below it. When you click in the autocomplete it registers the click in the next cell. How can I fix this?
Your issue is you are adding it to the view and not the tableview which resides in the UIView as well as having a section header that will probably block it out as well. I see your y position is only 53, so your header is likely blocking it out.
I am not 100% sure where you want your result to be viewed and used, that's not clear in your question. If you want your view to be above everything else you could:
"I have a UITableViewCell with a UITextField in it. When the user starts typing in this textfield, an autocomplete view appears." - add the result view to your cell, not the main view; [cell.contentView addSubview...
Shift your tableview down by changing it's y position to self.autocomplete.view.frame.size.height. Add a nice little animation to it as it changes position too, always something that bit extra.
Consider adding it as a subview to your TableView and bringing to front, should work.
(little bit extra on the cell.contentView)
I am using a custom class which is subclassing UITableViewCell. Now, when tableview goes in edit mode, I adjust the UIComponents on the cell inside layoutSubviews of my custom class. Now, when user tap on the "-" button the layoutSubviews get called once again and the UIComponents on the cell again repositions themselves which causes a weird UI flicker. I tried with below code in layoutSubviews but then UIComponents on the cell does not reposition themselves when user tap on edit and table comes in edit mode. Is there any graceful way to handle this.
if (self.editingStyle == UITableViewCellEditingStyleDelete) {
return;
}
Ok. Found this property which is set when user tap on the - button to show the delete button:
self.showingDeleteConfirmation
I have an application developed in iOS4 using XiBs. I got it working all good with iOS6.1 and earlier. But for some buttons, IBAction is not getting called if it is iPhone and iOS 7.0. Also it is working fine with iPad and iOS 7.0. Of course, I am using different Xibs for iPhone and iPad.
Here is the code. It is pretty basic. But just not getting into it.
- (IBAction) didReceiveMapButtonPress {
NSLog(#"IN DID RECEIVE MAP BUTTON PRESS");
if ([self wasReferredFromMap]) {
[[self navigationController] popViewControllerAnimated:YES];
} else {
[self pushMapViewController];
}
}
Many of the developer used custom view to show custom cell on Table view for older version of iOS. If you are one of them, then you will have to face a problem that your button click action will no longer work with iOS7.
How to resolve this:
You have three options:
Option 1: Create the new lay out with new table cell instead of taking view. and put all layouts again in table cell.
I know, this will require a lot of effort.If you don't want to do this, we have a very small hack for it:option 2
Option 2: Create a IBOutlet for your button and add this button as a subview of your cell's content view.
[self.myCell.contentView addSubview:self.btn_click];
The above line of code will add btn_click as a subview of you content view. Now button click action should work.
Option 3:
The best way :
i) Take An outlet UITableViewCell.
ii) Make existing view as subview of new table cell.
iii) Disconnect the connection of custom cell to existing view and connect it to new UITableViewCell.
thats it, Your IBAction will work now.
May be you got the crash with error message that "class is not key value coding - compliant.". Check your old view connection and remove all connection having yellow mark.
When I faced with this problem, I had tons of cells from xibs. That's way I've create the category for UITableViewCell
#implementation UITableViewCell (customs)
- (void)awakeFromNib {
[super awakeFromNib];
[self reAddSubviews];
}
- (void)reAddSubviews {
for (UIView * o_vw in [[[self subviews] objectAtIndex:0] subviews]) {
if (o_vw != self.contentView) {
[o_vw removeFromSuperview];
[self.contentView addSubview:o_vw];
}
}
}
#end
Please make sure the TCell.xib for your UITableViewCell is correct.
Double check if this xib file has "Content view". If you can not see this item, that means your view is not a UITableViewCell, it probably is a UIView.
The correct method is to recreate this XIB file. you can do it like this:
NewFile(User Interface)--->Empty--->Device Family(iphone)--->Save as TCell.xib.
add UITableViewCell
copy your subview from your previous xib file to this view and connect the outlets. http://i.stack.imgur.com/WB4j3.png
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.
I added a bunch of UILabel views to a UITableViewCell's contentView, some of which may overlap. On tapping any of the labels, I want to trigger some actions. Also, I want to bring up the tapped label to the top.
Using a UITapGestureRecognizer on the labels, I can figure out which one is tapped and perform the actions. But bringing the tapped and overlapped label to the front does not work. This is what I am trying:
UILabel *foundLabel = ....; // find the label
for (UITableViewCell *acell in theTable.visibleCells) {
UIView *cellContentView = acell.contentView;
if ([cellContentView.subviews containsObject:foundLabel]) {
[cellContentView bringSubviewToFront:foundLabel];
NSLog(#"should bring to front...");
}
}
I do get the NSLog output above, so I know that the bringSubviewToFront is being called on the appropriate cell's contentView. But no change in the subview layout order.
Ideas?
One thing to explore is zposition on the uitablviewcell's layer.
This successfully put on tableviewcell in front of another for me:
cell1.layer.zPosition=3 ;//above
cell2.layer.zPosition=2 ;//below
bringSubviewToFront: didn't work for me either
Try insertSubview:belowSubview: where the latter subview is a super view such as tab bar, nav bar, table view.