2017-02-12 6 views
1

Это мое приложение:Редактирование ячейки точек при редактировании TableView

App image

Когда я нажмите кнопку Edit ('' Редигер ''), я получаю следующее:

This happens

Итак, мой вопрос: как сделать круглый красный круг и индикатор раскрытия скрытым во время редактирования таблицы? Как круг, так и индикатор раскрытия являются imageViews.

Вот код для пользовательской ячейки (я вырезан ненужные части):

class KundeavisCell: UITableViewCell { 

@IBOutlet weak var unreadImage: UIImageView! 
@IBOutlet weak var disclosureIndicatorImage: UIImageView! 

} 

И контроллер с таблицей вида:

class KundeaviserVC: UIViewController, UITableViewDelegate, UITableViewDataSource { 

@IBOutlet weak var tableView: UITableView! 

@IBOutlet weak var redigerOutlet: UIBarButtonItem! 

var stores = ["Rema 1000", "Coop Obs", "Coop Extra"] 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "KundeavisCell", for: indexPath) as! KundeavisCell 

    // Here i edit the cell 

    return cell 
} 

func numberOfSections(in tableView: UITableView) -> Int { 
    return 1 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return stores.count 
} 

@IBAction func tableViewEditingPressed(_ sender: Any) { 

    if tableView.isEditing { 
     tableView.setEditing(false, animated: true); 
     redigerOutlet.style = UIBarButtonItemStyle.plain; 
     redigerOutlet.title = "Rediger"; 

    } else { 

     tableView.setEditing(true, animated: true); 
     redigerOutlet.title = "Ferdig"; 
     redigerOutlet.style = UIBarButtonItemStyle.done; 

    } 
} 

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { 
    return true 
} 

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { 

    let itemToMove = stores[sourceIndexPath.row] 
    stores.remove(at: sourceIndexPath.row) 
    stores.insert(itemToMove, at: destinationIndexPath.row) 
} 

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { 
    return UITableViewCellEditingStyle.none 
} 

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { 
    return false 
} 

} 

Я знаю, что я могу отступ изображения влево, устанавливая ограничения на них, но я хочу полностью скрыть их. Я нашел вопрос об этом: Link, но, к сожалению, он был написан 5 лет назад и в Objective-C.

Любая помощь будет очень признательна, спасибо!

+0

К сожалению, я не кодирую в Swift. Однако попробуйте подкласс UITableViewCell и переопределите ** setEditing: animated: **, как указано в этом разделе: http://stackoverflow.com/questions/19678695/customising-cell-editing-style-in-uitableview-in-ios, оттуда вы можете настроить свои ImageViews на скрытые = YES/NO в зависимости от того, как вы редактируете/останавливаете редактирование. –

ответ

0

Этот код, на который вы ссылаетесь, по-прежнему действует до сих пор. У вас уже есть пользовательская реализация UITableViewCell, поэтому теперь реализована функция SetEditing, а в реализации скрывает/показывает ваши изображения.

override func setEditing(_ editing: Bool, animated: Bool) { 
    unreadImage.isHidden = editing 
    disclosureIndicatorImage.isHidden = editing 
} 

Это должно сработать.

+0

Эй, это сработало отлично. Большое спасибо за то, что помогли мне! –

+0

@AleksandarBibic проблем нет. Приятно было сработать. – apineda

 Смежные вопросы

  • Нет связанных вопросов^_^