我正在使用SWTableViewCell在tableView中显示我的friendsList。根据代码一切正常。问题是,我一次只需要一个活动单元。现在我可以通过一个接一个地滑动来刷所有单元格的菜单。我想要的是,当我在另一个单元格上滑动时,前一个单元格应该转到其原始状态。
这是我的单元格代码
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray *leftUtilityButtons = [NSMutableArray new];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
icon:[UIImage imageNamed:@"about-icon-md.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
icon:[UIImage imageNamed:@"chat-4-64.png"] ];
static NSString* identifier=@"addContactCell";
Cell *cell=(Cell *)[tableView dequeueReusableCellWithIdentifier:identifier];
Cell __weak * weakCell = cell;
[cell setAppearanceWithBlock:^{
weakCell.containingTableView = tableView;
weakCell.leftUtilityButtons = leftUtilityButtons;
weakCell.delegate = self;
} force:NO];
if (cell==nil)
{
SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:identifier
containingTableView:self.table // Used for row height and selection
leftUtilityButtons:leftUtilityButtons
rightUtilityButtons:nil];
cell.delegate = self;
}
return cell;
}
cell.backgroundColor=[UIColor clearColor];
[cell.contentView.layer setBorderColor:[UIColor colorWithRed:0.15f green:0.47f blue:0.17f alpha:0.1].CGColor];
[cell.contentView.layer setBorderWidth:1.0f];
indexvalueRow = indexPath.row;
indexValueSection =indexPath.section;
friendUser= [self findFriendUser];
[friendUser fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error)
{
if (object) {
NSLog(@"friend user = %@", friendUser);
NSString *friendName = [NSString stringWithFormat:@"%@ %@", friendUser[@"FirstName"], friendUser[@"LastName"] ];
cell.nameLabel.text= friendName;
cell.nameLabel.textColor = [UIColor darkGrayColor];
PFFile *userImageFile = friendUser[@"profilePic"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error)
{
if (!error) {
//NSLog(@"%@", imageData);
cell.profileImage.image = [UIImage imageWithData:imageData];
}
}];
}}
}];
return cell;
}
答案 0 :(得分:7)
实现此委托方法..
- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell {
return YES;
}