可滑动的按钮操作

时间:2015-07-14 20:30:57

标签: ios objective-c button

我正在开发一款适用于音乐应用的应用。主要的想法是让应用看起来像新的东西。我有一个表,表有它自己的单元格。我为单元格创建了Swipeable方法,因此当用户向右滑动时,它应显示DOWNLOAD按钮,当用户向左滑动时,它应显示PLAY按钮。任何人都可以帮助对这些按钮进行一些特定的操作吗?我可以添加警报或视图,但我不知道如何专门为PLAY / PAUSE按钮添加动作?

以下代码我正在使用?

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
        {
            /
            UIActionSheet  ----
            break;
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index {

    switch (index) {
        case 0:
        {
            UIAlertView  --
            break;
        }

====更新====

我想为音乐播放器创建一个APP,所以问题是我是否有一个通常使用动态或静态单元格的单元格。这些细胞可以向左和向右滑动。

现在,当我想向右滑动按钮时,按钮应显示“下载”,如果向左滑动则按钮应显示播放/暂停,按下按钮后,应开始播放歌曲。

如果清楚的话,请告诉我。

1 个答案:

答案 0 :(得分:0)

假设您的问题是“我如何将所有IBAction集中在一个位置,您可以使用UITableViewCell作为参数传递来确定发件人的indexPath是什么:

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
    // Step 1, figure out which UITableViewCell
    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)
                              [[sender superview] superview]];

    // Step 2, dispatch using the button index
    switch (index) ...

    // At this time, you have bothe the index of the button and the index of the cell
    // You can take action for all UITableViewCells in this single location

}
相关问题