Удалить строку из UitableView, когда у меня есть несколько разделов iOS (значения находятся в Dynamic NSMutabledictionarIOS

Программируем под IOS
Ответить
Anonymous
 Удалить строку из UitableView, когда у меня есть несколько разделов iOS (значения находятся в Dynamic NSMutabledictionar

Сообщение Anonymous »

Позвольте мне сначала описать мой сценарий.

Код: Выделить всё

key     value
---------------------------------------------------------
A       (Apple, Aim, Arise, Attempt, Airplane, Absolute)
B       (Bubble, Bite, Borrow, Basket)
C       (Cat, Correct)
D       (Dog, Direction, Distribute)
< /code>
code: < /p>
- (void)viewDidLoad
{
[super viewDidLoad];

if ([self.wordListArray count] != 0)
{
self.wordDic = [self sortedDictionary:self.wordInWordListArray];

// Sorted key array
self.keyArray = [[NSArray alloc] init];
NSArray *key = [[NSArray alloc] init];
key = [self.wordDic allKeys];
self.keyArray = [key sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
}
У меня есть nsarray keyarray , где у меня есть все мои nsdictionary Keys (алфавитно) . А затем в cellforroworatIndexpath я показываю все мои значения определенного ключа (алфавитно) .
Вот мой таблица Методы:
my tableview :

Код: Выделить всё

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.keyArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 28;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 28)];
// Add title label
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 18)];
[titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14.0f]];
NSString *string = [self.keyArray objectAtIndex:section];

[titleLabel setText:string];
[view addSubview:titleLabel];

return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return kHomeTableViewCellHeight;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *key = [self.keyArray objectAtIndex:section];
NSMutableArray *value = [self.wordDic objectForKey:key];

return [value count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = kHomeTableViewCellID;
HomeTableViewCell *cell = (HomeTableViewCell *)[self.homeTableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (!cell)
{
cell = [[HomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;

NSString *secTitle = [self.keyArray objectAtIndex:indexPath.section];
secData = [self.wordDic objectForKey:secTitle];
[secData sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSString *data = [secData objectAtIndex:indexPath.row];
[cell.wordLabel setText:data];

return cell;
}
< /code>
Все работает отлично. Но теперь я хочу удалить свои ряды. < /P>
- (void)tableView:(UITableView *) tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//Other code
..............
..............

// remove info from tableView array
[self.whichArraywillBeHere removeObjectAtIndex:indexPath.row];
[self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
в CommitititingStyle , с каким массивом я должен был заменить этот self.whicharraywillbehere массив? Потому что, во -первых, у меня нет разделения в этом методе, и во -вторых, я загружаю свои ряды, алфавитно. Итак, как я могу узнать, какой массив мне здесь следует использовать и каково это это indexpath ?

Подробнее здесь: https://stackoverflow.com/questions/349 ... are-in-dyn
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»