2012-06-09 93 views
0

我有許多單元格的表格視圖。如果我在其中任何一個上滑動,會出現一個刪除按鈕,如果按下它,單元格會消失,但當我重新加載表格時,它會再次出現。這是從加載該文件是這樣的一個txt文件:從UITableView和通訊文件中刪除單元格

row1, row2, row3, row4, row5... 

我怎樣才能從文件中刪除行之一,所以刪除例如ROW3 ...

...,現...

row1, row2, row4, row5... 

回答

0
// Example file contents 
NSString *fileContents = @"row1, row2, row3, row4, row5"; 

// Separate the titles into an array 
NSMutableArray *titles = [[fileContents componentsSeparatedByString:@", "] mutableCopy]; 

// Remove row3 (at index 2 because indexes start from 0 
[titles removeObjectAtIndex:2]; 

// Combine the array back into a string 
NSString *result = [titles componentsJoinedByString:@", "]; 

// Log the result for debugging 
NSLog(@"%@", result); 

打印:row1, row2, row4, row5

此示例代碼創建一個字符串,使L ooks像你的文本文件,將它拆分成一個數組,刪除一個索引,然後將修改後的數組合併成一個字符串。

希望你會發現一些有用的代碼(我收集你會已經有一些或類似的使用)。

+0

但是由於我不知道對象的索引,它必須與行號相同 – Alessandro

+0

如果使用'tableView:didSelectRowAtIndexPath:'委託方法,只需使用'indexPath.row'來獲取所選行的索引。 – Greg

相關問題