Use UITableViewCellDeleteConfirmationControl to know what is the current cell's subview - ios

Is it OK to use UITableViewCellDeleteConfirmationControl this way:
- (void)layoutSubviews {
[super layoutSubviews];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.0f];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellDeleteConfirmationControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 200;
subview.frame = newFrame;
}
else if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 100;
subview.frame = newFrame;
}
else if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellReorderControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 200;
subview.frame = newFrame;
}
}
[UIView commitAnimations];
}
Even though UITableViewCellDeleteConfirmationControl is not a public class?

Since you're comparing string equality you're not exposing any private API's and therefore should be eligible for AppStore submission.
I've been successfully able to use this equality check in my own app that's made it to the AppStore.

First, a class is not a string. You should use NSStringFromClass([subview class]) to get a string representation of the class name.
Second, having the entire class name as a string literal is a big risk, and you should not have it so obvious. For instance, you could test if the name contains a portion of the name you are looking for: [className rangeOfSubstring:#"DeleteConfirmation"].location != NSNotFound.
Third, the reason this is not exposed is because it is private implementation of tableview cells. A good example why you shouldn't is on iOS7, the entire implementation of cells has been changed completely. The classes you mention in your example are no longer used.

Related

How can I perform a check on all check UITextField's in if condition

I have been looking out for solutions but haven't found one so far, please refer to the answer to this, i want to know if there is a way i can perform the check on all UITextFields, instead of having a hard coded value, thanks for help.
first your make sure that all textField have their delegate set to self ( means your viewController)
Ex. [myTextField setDelegate:self];// you can also set the delegate in Storyboard or xib directly
Then add a instance variable in your class implementation like -
#implementation myViewController
{
UITextField *activeField;
}
and then simply implement the method as below
in your textFieldShouldBeginEditing, set activeField
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
activeField = textField; // HERE get reference of your active field
return true;
}
There is a very nice method provided for all handling
CGRectContainsRect
if (!CGRectContainsRect(viewableAreaFrame, activeTextFieldFrame))
{
/*Scroll or move view up*/
}
Implement below in your keyboardWillShow method
EX.
- (void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
float viewWidth = self.view.frame.size.width;
float viewHeight = self.view.frame.size.height;
CGRect viewableAreaFrame = CGRectMake(0.0, 0.0, viewWidth, viewHeight - keyboardHeight);
CGRect activeTextFieldFrame = [activeTextField frame];
if (!CGRectContainsRect(viewableAreaFrame, activeTextFieldFrame))
{
/*Scroll or move view up*/
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height;
self.view.frame = f;
}];
}
}

Changing the position of the red minus button in a UITableViewCell while in Edit Mode

This code worked great inside a UITableViewCell subclass on iOS 5 and 6:
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
//Use your desired x value
newFrame.origin.x = 280;
subview.frame = newFrame;
}
While debugging my app on iOS 7 i've found that all the subviews above are called UITableViewCellContentView and there is no way knowing where the UITableViewCellEditControl subview is.
Is there a better solution for doing the above?
While debugging this I've found that all the subviews in iOS 7 are now called 'UITableViewCellEditControl". I tried logging all the subviews subviews and found that UITableViewCellEditControl is now a subview of a subview. This is an ugly temporary solution:
for (UIView *subview in self.subviews)
{
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 280;
subview.frame = newFrame;
}
else
{
if(IS_OS_7_OR_LATER)
{
for(UIView *subsubview in subview.subviews)
{
if ([NSStringFromClass([subsubview class]) isEqualToString:#"UITableViewCellEditControl"]) {
CGRect newFrame = subsubview.frame;
newFrame.origin.x = 280;
subsubview.frame = newFrame;
}
}
}
}

AdWhirl delegate not receiving messages

I am new to Adwhirl and am having some problems. I am setting my mainScreen controller as the delegate for AdView. While I am in this view, the ads refresh just fine. When I switch to another view though, the delegate no longer received any new ads(the delegates selectors are not fired). Is there a reason for this? I want one adView for my whole app, so I am passing a pointer around to it everywhere and adding it as a subview to the proper view.
Here is some code:
#pragma mark AdWhirl required delegate methods
- (NSString *)adWhirlApplicationKey {
return MY_AD_WHIRL_APPLICATION_KEY;
}
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
adView.hidden = NO;
if (self.view.window) {
[UIView beginAnimations:#"AdWhirlDelegate.adWhirlDidReceiveAd:"
context:nil];
[UIView setAnimationDuration:0.7];
CGSize adSize = [adView actualAdSize];
CGRect newFrame = adView.frame;
newFrame.size = adSize;
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;
newFrame.origin.y = self.view.bounds.size.height - 50;
adView.frame = newFrame;
[UIView commitAnimations];
}else {
[UIView beginAnimations:#"AdWhirlDelegate.adWhirlDidReceiveAd:"
context:nil];
[UIView setAnimationDuration:0.7];
CGSize adSize = [adView actualAdSize];
CGRect newFrame = adView.frame;
newFrame.size = adSize;
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;
//newFrame.origin.y = self.view.bounds.size.height - 50;
adView.frame = newFrame;
[UIView commitAnimations];
}
}
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo
{
adView.hidden = YES;
}
Note: The mainScreen controller is the one my app starts with..so it is always resident in memory. This is responsible for pushing the other views on screen. Am I missing something to get this working?

Change UITableViewCell's minus sign animation

I have an issue with editing table view:
I changed the minus sign location in edit mode to the right side of the cell.
The problem is that the button is sliding from the left and it makes it looks weird.
Is there a way to change this animation?
Also, there is an animation when undoing the delete option (clicking the minus sign when the red delete button is displayed), any idea why?
Here is a video showing the issue:
---edit---
This is how I changed the position:
- (void)layoutSubviews {
[super layoutSubviews];
//Indent to the left instead of right
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if ((self.editing
&& ((state & UITableViewCellStateShowingEditControlMask)
&& !(state & UITableViewCellStateShowingDeleteConfirmationMask))) ||
((state & UITableViewCellStateShowingEditControlMask)
&& (state & UITableViewCellStateShowingDeleteConfirmationMask)))
{
float indentPoints = self.indentationLevel * self.indentationWidth;
self.contentView.frame = CGRectMake(indentPoints - 35,
self.contentView.frame.origin.y,
self.contentView.frame.size.width - indentPoints,
self.contentView.frame.size.height);
}
//Change editAccessoryView location
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.0f];
//If can't use private classes (UITableViewCellDeleteConfirmationControl..), use [self.subviews objectAtIndex:0];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellDeleteConfirmationControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 10;
subview.frame = newFrame;
}
else if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 280;
subview.frame = newFrame;
}
else if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellReorderControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 200;
subview.frame = newFrame;
}
}
[UIView commitAnimations];
}
- (void)willTransitionToState:(UITableViewCellStateMask)aState {
[super willTransitionToState:aState];
self.state = aState;
}
---edit2---
I identified that the part that causes the minus sign jumping issue is the
//Change editAccessoryView location.
Without it there is no jumping but the minus button is back on the left side of the cell.
Any way around that?
Just a guess, but have you tried turning the view upside-down? You might be able to use a UIView transform.
(Code from the Internet, not sure how reliable it is)
CGAffineTransform rotateTransform;
rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI);
myView.transform = rotateTransform;

Custom UITableCell: Why delete icon appears on the content of the cell view?

I have custom cell in my tableview. when uitable view is in the editing mode. the rounded delete icon appears on the content of the cell.
How do I move the content to the right so to make place for the that little red rounded button.
In custom cell view layoutsubview should happen something. which subview of cell view should i resize?
thanks in advance
please take a look at my current code
- (void) layoutSubviews
{
[super layoutSubviews];
CGFloat width = self.width - _productImage.right - 20.f;
if (self.accessoryView)
{
width -= self.accessoryView.width;
}
_productName.width = width;
_productDescription.width = width;
_productPrice.width = width;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:3.0f];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellDeleteConfirmationControl"]) {
CGRect newFrame = self.contentView.frame;
self.contentView.frame = CGRectMake(40, self.contentView.frame.origin.y, newFrame.size.width, newFrame.size.height);
}
else if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
CGRect newFrame = self.contentView.frame;
self.contentView.frame = CGRectMake(40, self.contentView.frame.origin.y, newFrame.size.width, newFrame.size.height);
}
else if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellReorderControl"]) {
CGRect newFrame = self.contentView.frame;
self.contentView.frame = CGRectMake(40, self.contentView.frame.origin.y, newFrame.size.width, newFrame.size.height);
}
}
[UIView commitAnimations];
}
You can check the tableview.isEditing property.
If that is YES, then update the cell.contentView frame to x-difference otherwise use the default one.
Hope this is what you required.
Enjoy Coding :)

Resources