简体   繁体   中英

IOS Change Accessory View Cell Image in Uitableview based on NSMutableArray value

I have a UITableview That I display a list of users and their profile pictures. On the right hand side of the UITableview I have added a image for the Cell Accessory View.

I have a NSMutableArray "isFollowingLeader" that has 2 different values in it. 0 and 1 being the values stored in my array.

I want to be able to change or set the cell.accessoryView based on the isFollowingLeader array.

So If the isFollowingLeader array is 0 at index path of UITableview I want to set the image of the cell.accessoryView to my image of ic_add_contact.png at index path of UITableview and if the array is 1 at index path I want to show ic_checkmark_square.png

isFollowingLeader Array in NSlog (
1,
0,
0,
0,
1,
0,
0,
0
)

self.isFollowingLeader = [NSMutableArray arrayWithArray:[prefs arrayForKey:@"piccingFollowerisLeader"]];


if ([self.isFollowingLeader objectAtIndex:[indexPath row]] == 0) {

    // Sets the image for the  Accessory View for cell
    UIImageView *arrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_add_contact.png"]];
    cell.accessoryView = arrow;
}

else  {

    // Sets the image for the  Accessory View for cell
    UIImageView *arrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_checkmark_square.png"]];
    cell.accessoryView = arrow;
}

在此处输入图片说明

Not entirely sure what your question is, I'm assuming its not working for you?

This line is wrong....

if ([self.isFollowingLeader objectAtIndex:[indexPath row]] == 0)

You are asking if the object is 0, not the value of the object, so it should be

if ([[self.isFollowingLeader objectAtIndex:[indexPath row]] integerValue] == 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM