小编but*_*aby的帖子

如何在一个视图控制器中使用两个自定义UITableViewCells创建两个表视图?

我正在尝试UITableViews使用两个自定义创建二合一视图控制器UITableViewCells.我有以下内容:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if tableView == self.tableView {
        let cell = tableView.dequeueReusableCellWithIdentifier("CustomOne") as! CustomOneTableViewCell
        return cell
    }

    if tableView == self.autoSuggestTableView {
        let cell = tableView.dequeueReusableCellWithIdentifier("CustomTwo") as! CustomTwoTableViewCell
        return cell
    }
}
Run Code Online (Sandbox Code Playgroud)

但我一直收到错误:

Missing return in a function expected to return 'UITableViewCell'
Run Code Online (Sandbox Code Playgroud)

在方法结束时我必须返回什么?

ios swift

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

如何在 Swift 中的 PDFKit 中使用小部件字段类型签名?

我有点不确定如何在 PDFKit 中使用签名小部件字段类型。我尝试了以下但运气不佳:

let annotation = PDFAnnotation(bounds: CGRect.init(x: 100, y: 100, width: 100, height: 50), forType: .widget, withProperties: nil)
annotation.widgetFieldType = .signature
annotation.widgetStringValue = "Hello"
pdfView.currentPage?.addAnnotation(annotation)
Run Code Online (Sandbox Code Playgroud)

swift

5
推荐指数
0
解决办法
319
查看次数

更改UISearchBar取消按钮的字体样式

我正在尝试将UISearchBar取消按钮的字体更改为"OpenSans",但我无法访问任何属性.我只能更改UISearchBar的色调颜色,它会改变搜索栏取消按钮文本和搜索栏UITextField光标颜色的颜色:

searchBar.tintColor = UIColor(red: 187.0/255.0, green: 187.0/255.0, blue: 187.0/255.0, alpha: 1.0)
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个目标?

swift

4
推荐指数
1
解决办法
2110
查看次数

从URL路径中删除file:///前缀

如何从URL文件路径中删除file:///前缀:

 NSLog(@"File downloaded to: %@", filePath);
Run Code Online (Sandbox Code Playgroud)

当前它打印为:

file:///Users/Library/Developer/CoreSimulator/Devices/EF752245-9692-4607-B84C-6133202A846B/data/Containers/Data/Application/08686F05-C513-4BDF-A20C-EF3AE1201D54/Documents/2017-02-12_1476366438.zip
Run Code Online (Sandbox Code Playgroud)

编辑:

我想我可以做到的:

NSLog(@"File downloaded to: %@", [[filePath absoluteString] stringByReplacingOccurrencesOfString:@"file:///" withString:@""]);
Run Code Online (Sandbox Code Playgroud)

但是在NSString上没有构建可以删除该前缀的任何东西吗?

objective-c ios

3
推荐指数
1
解决办法
1361
查看次数

如何找到数组中的最小数字?

我正在编写一个算法来查找数组中的最小数字但是我的print语句一直说最低的数字是0.我有以下内容:

var list = [5, 4, 3, 5, 2, 50, 8, 10, 300]

func findMin(numbers: NSArray) {

    var minValue = numbers[0]
    var isSmallest: Bool

    for i in 0...numbers.count {
        isSmallest = true
        for j in 0...numbers.count {
            if i > j {
                isSmallest = false
            }
        }

        if isSmallest {
            minValue = i
        }

    }
    print("Smallest value in the list is \(minValue)")
}

findMin(numbers: list as NSArray)
Run Code Online (Sandbox Code Playgroud)

我的print语句返回为:

"Smallest value in the list is 0\n"
Run Code Online (Sandbox Code Playgroud)

我觉得算法是正确的.有任何想法吗?

编辑:回答了我自己的问题

我在迭代索引而不是实际值.感谢评论中的一位用户.正确的代码应该是:

var list …
Run Code Online (Sandbox Code Playgroud)

arrays swift

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

如何跟踪使用 NSIndexPath 选择的单元格?

我有多个部分UITableView,每个部分都有不同数量的UITableViewCells.

我想跟踪为每个部分选择的单元格并为已选择的单元格显示图像。

所以我在考虑将它们存储在一个数组中:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
     someArray.append(indexPath)
}
Run Code Online (Sandbox Code Playgroud)

然后显示已选择单元格的图像:

 for indices in self.someArray {
     if indices == indexPath {
         cell.button.setImage(UIImage(named: "selected"), forState: UIControlState.Normal)
     } else {
         cell.button.setImage(UIImage(named: "unselected"), forState: UIControlState.Normal)
     }
 }
Run Code Online (Sandbox Code Playgroud)

我还想使每个部分一次只能选择一个单元格,并且每个部分的每个选择都保持不变。

选择只是不保持原样。每次我在部分 0 中为某行进行选择时,它也会为我的其他部分选择相同的行索引。

我该如何解决?

uitableview ios swift

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

标签 统计

swift ×5

ios ×3

arrays ×1

objective-c ×1

uitableview ×1