UITableView section index titles array cannot consist of a single "•" index title.

Originator:alin.claudiu.radut
Number:rdar://34570716 Date Originated:
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
 
Area:
UIKit

Summary:
A table view with section index titles cannot have  a single section index title consisting of the • character. 

Steps to Reproduce:
Set up a table view with one section and return section title and section index titles where the single section title is "•". If any other section index title except • is returned alongside the existing index title, the table view behaves as expected.
See attached file. Can be pasted over MasterViewController.swift from a default Master-Detail iOS app created with Xcode.

Expected Results:
The table will show the dot character as a section index title on the right of the table view.

Actual Results:
The application crashes with the following exception:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000103e6fb0b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00000001038db141 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000103da4ffb -[__NSArrayM objectAtIndex:] + 203
	3   UIKit                               0x000000010469526b -[UITableViewIndex _displayTitles] + 292
	4   UIKit                               0x0000000104695692 -[UITableViewIndex _cacheAndMeasureTitles] + 165
	5   UIKit                               0x00000001046967b6 -[UITableViewIndex setTitles:] + 119
	6   UIKit                               0x00000001043cca09 -[UITableView _updateIndexDisplayedTitles] + 65
	7   UIKit                               0x00000001043ccf90 -[UITableView _updateIndex] + 308
	8   UIKit                               0x00000001043e5ede -[UITableView noteNumberOfRowsChanged] + 159
	9   UIKit                               0x00000001043e5508 -[UITableView reloadData] + 2013

Version/Build:
iOS 10.3.3

Attached file:
import UIKit

class MasterViewController: UITableViewController {

    var detailViewController: DetailViewController? = nil
    var objects = [Any]()


    override func viewDidLoad() {
        super.viewDidLoad()

        for  _ in 0..<10 {
            objects.insert(NSDate(), at: 0)
        }
        tableView.reloadData()
    }
    
    func insertNewObject(_ sender: Any) {
        objects.insert(NSDate(), at: 0)
    }
    
    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return sectionIndexTitles(for: tableView)![section]
    }
    
    override func sectionIndexTitles(for tableView: UITableView) -> [String]? {
        return [
            "•", // this will crash. uncomment the line below and it will not crash any more.
//            "A",
        ]
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return sectionIndexTitles(for: tableView)!.count
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objects.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

        let object = objects[indexPath.row] as! NSDate
        cell.textLabel!.text = object.description
        return cell
    }
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!