Check all cells Accessory view

Sammy.GSammy.G USMember
edited November 2015 in Xamarin.iOS

Hi folks

I am trying to write this in a button_tap event. I have a table view and each cell has accessoryView = UISwitch. I am trying to get all cell data (a string) where its switch is ON

Best Answers

  • Tom-PrattTom-Pratt GB ✭✭
    Accepted Answer

    Does your tableview use static cells or dynamic prototypes? If it's static then you can probably access the information you need like this

    var indexPaths = Table.IndexPathsForVisibleRows;
    foreach (var indexPath in indexPaths) {
        var cell = Table.CellAt (indexPath);
        if (cell.AccessoryView ...
    }
    

    If it's dynamic then you need to access the information from the underlying data itself. The data that powers your TableViewSource class.

Answers

  • Tom-PrattTom-Pratt GBMember ✭✭
    Accepted Answer

    Does your tableview use static cells or dynamic prototypes? If it's static then you can probably access the information you need like this

    var indexPaths = Table.IndexPathsForVisibleRows;
    foreach (var indexPath in indexPaths) {
        var cell = Table.CellAt (indexPath);
        if (cell.AccessoryView ...
    }
    

    If it's dynamic then you need to access the information from the underlying data itself. The data that powers your TableViewSource class.

  • Sammy.GSammy.G USMember

    For now I have hard coded 4 rows in my table so this should work. I am very new to Mobile app dev so I am coding by asking questions :smile:

  • Sammy.GSammy.G USMember

    I know that AcessotyView is a UISwitch but how I can check its state?
    Thanks

Sign In or Register to comment.