logo
down
shadow

Maintain A state of button in UITableViewCell


Maintain A state of button in UITableViewCell

Content Index :

Maintain A state of button in UITableViewCell
Tag : development , By : ussballantyne
Date : September 12 2020, 11:00 PM

help you fix your problem Take one array [Int] and store your indexpath.row when click any of the button state and in cellForRowAt indexPath: method check indexpath and manage the state if indexpath exists on your array.
Another way to get it done is by adding extra keys into your data model.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to maintain a Home Button Presistent state of an app in Android?


Tag : android , By : user183954
Date : March 29 2020, 07:55 AM
With these it helps When you do that Android will call:
onRestart() onStart() onResume()

How can i maintain the selected state in button in iPhone


Tag : iphone , By : Guy Kastenbaum
Date : March 29 2020, 07:55 AM
it helps some times I have created scroll view and sets the buttons are in the scroll view. The Buttons are scrolling horizontally and it works fine. If i clicked the button, i set background image as "Selected State" in button. My problem is how can i changed the selected state in different button, when clicking it and how can i deselected the "selected state" button when clicking the another button. , I solved this task in the following way:
init method:
- (void)init {

....INITIALIZE SCROLLVIEW HERE.....

    for ( int i = 0; i < 10; i++ ) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

        [btn setFrame:.....];
        [btn setImage:_IMAGE_ forState:UIControlStateNormal];
        [btn setImage:_IMAGE2_ forState:UIControlStateSelected];
        [btn setTag:i + 1000];

        [btn addTarget:self action:@selector(setSelectedButton:) forControlEvents:UIControlEventTouchUpInside];

        [self addSubview:btn];
    }
}

- (IBAction)setSelectedButton:(id)sender {
    [self setSelectedButtonByIndex:((UIButton *)sender).tag - 1000];
}

- (void)setSelectedButtonByIndex:(NSInteger)index {
    if ( selectedElemId >= 0 ) {
        UIButton *btn = (UIButton *)[self viewWithTag:selectedElemId + 1000];
        [btn setSelected:NO];
    }

    UIButton *btn = (UIButton *)[self viewWithTag:index + 1000];
    [btn setSelected:YES];

    selectedElemId = btn.tag - 1000;
}

IOS: Maintaining button state in uitableviewcell


Tag : ios , By : janik
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The problem is that every time you create or reuse a cell you're giving it a new like button, so when you reuse a cell where the like button has been activated, you're giving it a deactivated like button but the old, activated like button is still there as well.
Instead of creating a like button every time you need a cell, you should just be setting the state of an existing like button. See the answers to this question for some possible ways of handling that.

UITableview or AQGridView maintain state of button in cell


Tag : ios , By : Malikul
Date : March 29 2020, 07:55 AM
Hope that helps As you said, add a target to you button to whatever method you want. In that method, you can then get the rows index by using
              NSSet *touches = [event allTouches];
              UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:tableview];
      NSIndexPath *indexPath = [tableview indexPathForRowAtPoint: currentTouchPosition];
              NSUInteger row = [indexPath row];

How to maintain UITableViewCell state when UITableView scrolling?


Tag : ios , By : Yohan Lee
Date : March 29 2020, 07:55 AM
wish of those help You should have an array of boolean for isExpand , and in cellForRow check if it's true change height of row .
First of all make array :
var expandingStateArray = [false,false,false,false,false,false,false,false,false,false]
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: cellWithButton, for: indexPath) as! WithButtonTableViewCell

if expandingStateArray[indexPath.row] {
            titleLabel.numberOfLines = 0
            expandButton.setTitle("Close.", for: .normal)
        }else{
            titleLabel.numberOfLines = 2
            expandButton.setTitle("Show More.", for: .normal)
        }
        cell.titleLabel.text = text
        cell.expandButton.addTarget(self, action: #selector(btnPressed), for: .touchUpInside)
        cell.expandButton.tag = indexPath.row
        cell.layoutIfNeeded()


        return cell
    }
    }
@objc func btnPressed(sender: UIButton) {

let indexPath = IndexPath(row: sender.tag, section: 0)

expandingStateArray[sender.tag] = !expandingStateArray[sender.tag]

tableView.beginUpdates()
tableView.reloadRows(at: [indexPath], with: .none)
tableView.endUpdates()

}
}
Related Posts Related QUESTIONS :
  • Add elements into an array then find distinct,
  • Angular8 - error TS2304: Cannot find name
  • Manually polling streams in future implementation
  • How do you perform receipt validation for Android on Xamarin Forms
  • What is the rule behind instruction count in Intel PIN?
  • How to draw some text when click a button in wxWidgets?
  • Restrict entity types in Spacy NER
  • How to animate CN1 Slider progress on load
  • Issue with bwa mem process not running on all output files from previous process
  • Delete videos from playlist using YouTube API
  • How to restart the Hyperledger Composer Playground locally
  • How to configure email alerts in Zabbix Server?
  • Simulator is not working for smart home action with all configured session
  • How parse data using join on Objection.js
  • Assign an array to a property in a Chapel Class
  • Netlogo: How can I obtain the accumulate value in Netlogo?
  • How to populate datasource for listview using api response in react native?
  • Why does gmail API when using history.list method send message ids without the field what action has been preformed on t
  • How to run an append query in ms access vba as part of a transaction
  • Wrong dates shown in Jekyll-based blog
  • How to concatenate two document lists in a webMethods flow service?
  • How to properly set up a site map addition in a customization project
  • IBM Content Collector error calling external Web Service
  • Is (0*1*)* equal to (0 | 1)*?
  • How do I configure phpMyAdmin to start with a blank sql query from the SQL tab?
  • "Objects are not valid as a React child" Redux error when conditionally connecting a component?
  • Displacy results are not showing
  • Strapi / Graphql. What am i doing wrong?
  • How to add Search bar for django template?
  • lookup in presto using single column against a range in lookup table
  • How can you stop videos being stolen on website?
  • Can't code substitution happen in Hybrid Flow?
  • Removed widget remains on parent
  • setup saga middleware with redux-starter-kit's configureStore()
  • How to get cookies from response of scrapy splash
  • I need to do a firebase stream and not a Http Get
  • Unable to compile node-runtime
  • SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause'
  • How to extract only the number from a variable
  • disable linter in DAML studio
  • RxJS: How to set exhaustMap concurrent?
  • How to remove perforce (p4) on Ubuntu
  • How do they know mean and std, the input value of transforms.Normalize
  • Why this type is not an Interface?
  • SugarCRM Rest API set_relationship between Contacts and Documents
  • Jira dashboard organization
  • Web worker importScripts fails to place script variables in global scope
  • Always errors - The "path" argument must be one of type string, Buffer, or URL. Received type undefined
  • How to create an observable of a stream of infinite items
  • Not efficiently to use multi-Core CPU for training Doc2vec with gensim
  • webGL gl_Position value saving outside shaders
  • Is it okay for a resolver to have side effects besides resolving the type?
  • Move 32bit register into a 8 bit register
  • Is there a way to update, not overwrite, worker_env for a Dask YarnCluster within a script?
  • Lotus Notes Deployment
  • How Do I Add Active Directory To APIM Using Terraform?
  • How to get the old parameter values in Blazor OnParameterSet?
  • How to debug "ERROR: Could not reach the worker node."?
  • How chain indefinite amount of flatMap operators in Reactor?
  • extract dates and times from string in Redshift
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com