logo
down
shadow

Adding checkmark to selected table cell also checks another table cell


Adding checkmark to selected table cell also checks another table cell

By : Dylan Rich
Date : November 24 2020, 05:44 AM
I think the issue was by ths following , In your cellForRowAtIndexPath you can't be configuring the cell properly when the cell gets reused. You should always be setting (and resetting) all of the properties of the cell from your data model.
code :


Share : facebook icon twitter icon
Adding a sliding view to a table cell when selected

Adding a sliding view to a table cell when selected


By : Anshu Anand
Date : March 29 2020, 07:55 AM
seems to work fine You would use a UITableViewCell subclass with a foreground and a background view and a UIPanGestureRecognizer. this recognizer will trigger the swipe and handles the moving of the foreground view.
that said, you'll find a implementation here: https://github.com/spilliams/sparrowlike
code :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
    [panGestureRecognizer setDelegate:self];
    [cell addGestureRecognizer:panGestureRecognizer];

    return cell;
}

#pragma mark - Gesture recognizer delegate
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer
{
    CustomCell *cell = (CustomCell *)[panGestureRecognizer view];
    CGPoint translation = [panGestureRecognizer translationInView:[cell superview] ];
    return (fabs(translation.x) / fabs(translation.y) > 1) ? YES : NO;
}

#pragma mark - Gesture handlers

-(void)handlePan:(UIPanGestureRecognizer *)panGestureRecognizer
{
    float threshold = (PAN_OPEN_X+PAN_CLOSED_X)/2.0;
    float vX = 0.0;
    float compare;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:(CustomCell *)[panGestureRecognizer view] ];
    UIView *view = ((CustomCell *)panGestureRecognizer.view).frontView;

    switch ([panGestureRecognizer state]) {
        case UIGestureRecognizerStateBegan:
            if (self.openCellIndexPath.section != indexPath.section || self.openCellIndexPath.row != indexPath.row) {
                [self snapView:((CustomCell *)[self.tableView cellForRowAtIndexPath:self.openCellIndexPath]).frontView toX:PAN_CLOSED_X animated:YES];
                [self setOpenCellIndexPath:nil];
                [self setOpenCellLastTX:0];
            }
            break;
        case UIGestureRecognizerStateEnded:
            vX = (FAST_ANIMATION_DURATION/2.0)*[panGestureRecognizer velocityInView:self.view].x;
            compare = view.transform.tx + vX;
            if (compare > threshold) {
                [self snapView:view toX:PAN_CLOSED_X animated:YES];
                [self setOpenCellIndexPath:nil];
                [self setOpenCellLastTX:0];
            } else {
                [self snapView:view toX:PAN_OPEN_X animated:YES];
                [self setOpenCellIndexPath:[self.tableView indexPathForCell:(CustomCell *)panGestureRecognizer.view] ];
                [self setOpenCellLastTX:view.transform.tx];
            }
            break;
        case UIGestureRecognizerStateChanged:
            compare = self.openCellLastTX+[panGestureRecognizer translationInView:self.view].x;
            if (compare > PAN_CLOSED_X)
                compare = PAN_CLOSED_X;
            else if (compare < PAN_OPEN_X)
                compare = PAN_OPEN_X;
            [view setTransform:CGAffineTransformMakeTranslation(compare, 0)];
            break;
        default:
            break;
    }
}
-(void)snapView:(UIView *)view toX:(float)x animated:(BOOL)animated
{
    if (animated) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:FAST_ANIMATION_DURATION];
    }

    [view setTransform:CGAffineTransformMakeTranslation(x, 0)];

    if (animated) {
        [UIView commitAnimations];
    }
}
Xcode logging only previously selected table view cell once a new cell is selected

Xcode logging only previously selected table view cell once a new cell is selected


By : Chenxuan Zhang
Date : March 29 2020, 07:55 AM
I hope this helps you . Wrong method. You want didSelectRowAtIndexPath. Yours is Deselect instead of Select
Tick a checkbox in a table cell by clicking anywhere in the table cell and change background color of that cell

Tick a checkbox in a table cell by clicking anywhere in the table cell and change background color of that cell


By : user1986758
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You could restructure like this
code :
$('table tr td').on('click', function(e){
    var checkbox = $(this).find('input:checkbox');
    if (!$(e.target).is(':checkbox')) {
        checkbox.prop('checked', !checkbox.is(':checked'));
    }
    $(this).css('background-color', checkbox.is(':checked')?'#DFF0D8':'white');
});
Set checkmark for static table view cell

Set checkmark for static table view cell


By : abam1588
Date : March 29 2020, 07:55 AM
this will help Since you are using static cells, in which case you only have 3, you could set up IBOutlet in storyboard.
code :
@IBOutlet weak var cell1: UITableViewCell!
@IBOutlet weak var cell2: UITableViewCell!
@IBOutlet weak var cell3: UITableViewCell!
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) 
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{

    NSUserDefaults.standardUserDefaults().setObject("0", forKey: "Sort")
    NSUserDefaults.standardUserDefaults().synchronize()


    let defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults()
    var aString = defaults.valueForKey("Sort") as? String

    let cellIndex = aString?.toInt()

    if cell1.tag == cellIndex
    {
        cell1.textLabel!.text = "Hallo, I am cell 1"
        cell1.accessoryType = UITableViewCellAccessoryType.Checkmark
    }
    else if cell2.tag == cellIndex
    {
        cell2.textLabel!.text = "Hello, I am cell 2"
        cell2.accessoryType = UITableViewCellAccessoryType.Checkmark
    }
    else if cell3.tag == cellIndex
    {
        cell3.textLabel!.text = "Hello, I am cell 3"
        cell3.accessoryType = UITableViewCellAccessoryType.Checkmark
    }

}
swift table view adding custom checkmark to cell and remove checkmark from previous cell

swift table view adding custom checkmark to cell and remove checkmark from previous cell


By : Warren Kaye
Date : March 29 2020, 07:55 AM
it should still fix some issue
Keep track of which row is currently selected. Add a property to your ViewController:
code :
var selectedRow: NSIndexPath?
let paths:[NSIndexPath]

if let previous = selectedRow {
    paths = [indexPath, previous]
} else {
    paths = [indexPath]
}
selectedRow = indexPath
tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: .None)
if indexPath == selectedRow {
    // set checkmark image
} else {
    // set no image
}
Related Posts Related Posts :
  • Unclear about releasing CFDictionaryRef
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org