У меня есть UITableView, который заполняется ключами массива из NSMutableDictionary.iOS - Как получить метку строки таблицы из commitEditingStyle
Чтобы иметь возможность удалять эти массивы, мне нужно как-то получить ключ. Мои мысли были самыми легкими - это получить его от ярлыка строки.
Я использую этот код для загрузки словаря:
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:(NSString *)plistPath];
и это, чтобы удалить массив из словаря:
[dictionary removeObjectForKey:];
Но, очевидно, я пропускаю они ключ, как я не Не знаю, как его программно использовать. Какие-нибудь советы?
Приветствия,
Chris
<plist version="1.0">
<dict>
<key>(null)</key>
<array>
<string>Username</string>
<string>Password</string>
<string>http://www.google.com</string>
<string>/whatever</string>
</array>
<key>Hello</key>
<array>
<string>admin</string>
<string></string>
<string>https://www.whatever.com</string>
<string>/things</string>
</array>
</dict>
</plist>
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ViewerName"];
UILabel *label = (UILabel *)[cell viewWithTag:1000];
label.text = [viewerKeys objectAtIndex:indexPath.row];
return cell;
}
Удалить Код:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:(NSString *)plistPath];
NSString *key = [viewerKeys objectAtIndex:indexPath.row];
[dictionary removeObjectForKey:[NSString stringWithFormat:@"%@", key]];
[self.tableView reloadData];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
}
'[[dictionary allKeys] objectAtIndex: indexPath.row]' – 2013-02-14 17:00:57
Показать несколько строк вашего plist. (В Xcode щелкните правой кнопкой мыши и «Открыть как» -> «Исходный код»). Пожалуйста, поместите это в свой ** вопрос ** не как комментарий. – Mundi
@ H2CO3 Я думаю, что это не гарантирует правильный порядок .... – Mundi