【发布时间】:2014-09-12 23:34:15
【问题描述】:
我是 IOS 新手,所以我不能 100% 确定为什么在我的 SWTableViewCell 实现中没有调用委托方法(可以在此处找到的库:https://github.com/CEWendel/SWTableViewCell)
我有一个 tableViewController.h 文件,如下所示:
#import <UIKit/UIKit.h>
#import "SWTableViewCell.h"
#import <AVFoundation/AVFoundation.h>
@interface ICIRecordingsViewController : UITableViewController <SWTableViewCellDelegate, AVAudioPlayerDelegate>
@property (nonatomic, strong) NSArray *documentArray;
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
@property (strong, nonatomic) SWTableViewCell *previousCell;
@end
tableViewcontroller.m 文件导入以下内容:
#import "ICIRecordingsViewController.h"
#import "ICIRecordingCell.h"
@interface ICIRecordingsViewController ()
@end
ICIrecordingCell.h 文件如下所示:
#import <UIKit/UIKit.h>
#import "SWTableViewCell.h"
@interface ICIRecordingCell : SWTableViewCell
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UIButton *playButton;
@end
ICIRecordingCell.m 文件导入 ICIRecordingCell.h
滑动手势在单个单元格上注册并显示底层按钮,但是当我点击按钮时,委托方法没有被触发:
-(void) swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index{
switch(index){
case 0:{
UIActionSheet *shareActionSheet = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Share on FaceBook", @"Share on Twitter", nil];
[shareActionSheet showInView:self.view];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:{
NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];
//need to figure out how to delete the item from the file system
[self.tableView deleteRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
break;
}
default:break;
}
}
我在委托方法上设置了一个断点,但是当按钮被点击时没有任何东西被点击。有什么想法吗?
【问题讨论】:
-
对于任何想知道 SWTableViewCell 是什么的人,it's open source code found on GitHub。
-
谢谢 - 是的将编辑我的问题
-
SWTableViewCell 采用“
delegate”。你在哪里设置的? -
我在按钮中写入时已将其设置在 cellForRowAtIndexPath 方法中。它大致如下: cell.rightUtilityButtons = myButtons;然后 cell.delegate = self;返回单元格;
-
您应该编辑您的问题以显示“
cellForRowAtIndexPath”代码。
标签: ios uitableview delegates