Вот некоторый рабочий код, который добавляет галочку к элементу списка дел, когда он завершен:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
} return cell;
}
Что я хочу сделать, так это удалить код галочки и что-то вроде (основная логика):
if (toDoItem.completed) {
cellIdentifier.textLabel (NSAttributedString Strikethrough = YES)
} else {
cellIdentifier.textLabel (NSAttributedString Strikethrough = NO)
} return cell;
Я также пытался изменить NSString
на NSAttributedString
и NSMutableAttributedString
на основе некоторых других вопросов и ответов, которые я видел такой как этот вот так:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary* attributes = @{
NSStrikethroughStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle]
};
static NSAttributedString* cellIdentifier = [[NSAttributedString alloc] initWithString:@"ListPrototypeCell" attributes:attributes];
cell.textLabel.attributedText = cellIdentifier;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
} return cell;
}
Но я не уверен в точной реализации, например, как это вызвать в методе if (toDoItem.completed)
. Это должно поддерживаться только iOS7.
Как я могу получить эффект зачеркивания на метке ячейки таблицы, когда элемент будет завершен?