user2551413
user2551413

Reputation:

Changing the accessory view of cell in a user defined function

I want to change the accessory view of the cell. When the user clicks on the right navigation bar item an action occurs, in that action i want to change the accessory view. how can i do this, when i used this code its asking for NSindexPath thing so i have no which value i can give here , in order to change the view of all cells.

 MyCustomCell *cell = (MyCustomCell *) [self.tableView cellForRowAtIndexPath:helloIndexPath];
    if( cell.accessoryType ==  UITableViewCellAccessoryDisclosureIndicator)
    {
        cell.accessoryView = [[UIImageView alloc]initwithImage:[UIImage imageNamed:@"hello.png"]];
    }

Upvotes: 0

Views: 99

Answers (1)

amar
amar

Reputation: 4345

I guess you should put condition in table view - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Here you can put a if-condition.

if(flagForAction){
cell.accessoryView = [[UIImageView alloc]initwithImage:[UIImage imageNamed:@"hello.png"]];
}
else
{
cell.accessoryView = [[UIImageView alloc]initwithImage:[UIImage imageNamed:@"<no-Hello>.png"]];
}

All you need to do is set your flag and reload table at action. by calling [<your table> reloadData];

Upvotes: 1

Related Questions