相关疑难解决方法(0)

如何知道UITableview行号

我有一个UITableViewCellUISwitch作为accessoryView的每一个细胞.当我更改单元格中交换机的值时,如何知道交换机在哪一行?我需要切换值更改事件中的行号.

iphone uitableview uiswitch ios

38
推荐指数
2
解决办法
2万
查看次数

IOS 7 - 如何从放置在UITableViewCell中的按钮获取indexPath

我以编程方式创建了一个UITableView,并将UISwitch添加到它的单元附件视图中.

这是我在cellForRowAtIndexPath方法中的单元附件视图中的UISwitch代码.

UISwitch *accessorySwitch = [[UISwitch alloc]initWithFrame:CGRectZero];
[accessorySwitch setOn:NO animated:YES];
[accessorySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = accessorySwitch;
Run Code Online (Sandbox Code Playgroud)

这是单击按钮后调用的方法.

- (void)changeSwitch:(UISwitch *)sender{

    UITableViewCell *cell = (UITableViewCell *)[sender superview];

    NSIndexPath *indexPath = [self.filterTableView indexPathForCell:cell];
    NSLog(@"%ld",(long)indexPath);

 ……………. My other code…….
}
Run Code Online (Sandbox Code Playgroud)

我能够在iOS 6中打印索引路径值但是在iOS 7中它打印为nil,

我在iOS 7中遗漏了什么,或者在iOS 7中有其他方法来获取indexPath

谢谢,阿伦.

iphone uitableview ios ios7

29
推荐指数
3
解决办法
3万
查看次数

如何在tableView中使用Seque查找tapped按钮的indexPath

我有一个UITableView使用原型单元格.

细胞具有UIButton显示UIViewController(模态)使用的细胞Segue.

我的问题是:我如何将IndexPath单元格传递给第二个视图控制器

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"showGamerDetail"]) {

            //its not worked:
            NSIndexPath *indexPath = [self._tableView indexPathForSelectedRow];
            nDetailViewController *destinationViewController = segue.destinationViewController;
            destinationViewController.selectedRowTitle = [gamers objectAtIndex:indexPath.row];

        destinationViewController.indexPath = indexPath;
        destinationViewController.delegate = self;
    }
Run Code Online (Sandbox Code Playgroud)

uitableview ios

5
推荐指数
1
解决办法
1万
查看次数

在 UICollectionView Swift 中获取单击的 UICollectionViewCell 的索引

如何获取我在 Xcode 中使用 Swift for iOS 制作的 CollectionView 中单击的“Sheep”的索引?

class SheepsOverviewVC: 
UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "class", for: indexPath) as! ClassesCollectionCell
    if(sheeps.count > 0) {
        cell.ClassImageView.image = UIImage(named: sheeps[indexPath.row] as! String)
        cell.SheepName.text = names[indexPath.row] as? String
    }
    return cell
}
Run Code Online (Sandbox Code Playgroud)

我通过 Gui 在 TouchDown 上创建了一个发送事件:

@IBAction func clickingSheep(_ sender: UIButton) {
    print("This will show info about the Sheep")
    print(sender)
}
Run Code Online (Sandbox Code Playgroud)

但我得到的回应来自第二次印刷:

<UIButton: 0x7f9a63021d20; frame = (50 50; …

ios uicollectionview swift

0
推荐指数
1
解决办法
2247
查看次数

标签 统计

ios ×4

uitableview ×3

iphone ×2

ios7 ×1

swift ×1

uicollectionview ×1

uiswitch ×1