2014-02-06 62 views
0

我下面的代碼使IOS刷卡刪除功能並刪除行。問題是底層的數據結構沒有被刪除。我有3個單元格,Google-Bing-Yahoo,如果我刪除Google單元格刪除但Bing上移,變成indexPath.row 0並繼承谷歌以前的操作。我在哪裏錯過了「嘿,刪除行動到這個單元格」呼籲。或者也許這是我分配細胞的方式?我應該使用標籤嗎?刷卡刪除沒有刪除底層數據結構

////My Array 
someData = [[NSMutableArray alloc]init]; 
    [someData addObjectsFromArray:[NSMutableArray arrayWithObjects: @"Google", @"Bing", @"Yahoo", nil]]; 


////Allow cell editing & remove data 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

// Remove the row from data model 
[someData removeObjectAtIndex:indexPath.row]; 

// Request table view to reload 
[tableView reloadData]; 

} 


////Cell Chosen Action 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 


     if(indexPath.row == 0) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://google.com"]]; 
} 
     if(indexPath.row == 1) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://bing.com"]]; 
} 
     if(indexPath.row == 2) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://yahoo.com"]]; 
} 

回答

1

您didSelectRowAtIndexPath是說,無論如何,行0打開谷歌。當你刪除谷歌,第0行現在是冰,但你仍然打開谷歌。這樣做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: [NSString stringWithFormat:@"http://%@.com", [someData objectAtIndex:indexPath.row]]]]; 
} 

基本上你會形成與數組名的URL,不再需要任何的if語句和混亂。

+0

有道理。所以這是我的任務方法。謝謝。 – Jesse