@Carlos是對的 - 你不想從你創建的表示字符串中解析數據。您必須已經name
,quantity
和color
存儲變量的地方,你在cellForRowAtIndexPath
使用。如果數據已經存儲在陣列中,當你刪除單元格是否可以訪問,使用indexPath
找到數據的陣列。
下面是一個例子我前面,我的數據在陣列sourceAlbumNames
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return sourceAlbumNames.count;
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = sourceAlbumNames[indexPath.row] as String
return cell
}
我想你已經有這樣的事情對於刪除
func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
// handle delete (by removing the data from your array and updating the tableview)
sourceAlbumNames.removeAtIndex(indexPath!.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
從拍攝的東西舉行字符串轉換爲特定類型稱爲解析。我不會這樣做,我會儲存一些變量,從單元格創建的第一個地方。但是如果必須的話,你可以將字符串拆分並將這些部分解析爲適當的變量。 – Carlos
爲了從'String'中檢索值,我們可以使用正則表達式。請參閱文檔:https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSRegularExpression_Class/和一個不錯的教程 –