Сбой просмотра таблицы при нажатии на ячейку TableView
Когда я нажимаю на ячейку, я получаю сбой (приложение закрывается в iOS-симуляторе). Код ошибки:
"EXC_BAD_ACCESS (код = 1, адрес = 0x310cc493)
Вот код:
- КРАСНЫЙ ЭКРАН в титане
- Apple Watch OS2 beta 3 - приложение застряло на физических часах
- Текущее системное время на iOS
- Как изменить цвет текста всего текста в UIView?
- Ошибка Swift xcode: значение типа 'DetailViewController' не имеет члена 'Animal'
// .h #import <UIKit/UIKit.h> @interface ChecklistsViewController : UITableViewController @end // .m #import "ChecklistsViewController.h" @interface ChecklistsViewController () @end @implementation ChecklistsViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 100; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"]; UILabel *label = (UILabel *)[cell viewWithTag:1000]; if (indexPath.row % 5 == 0) { label.text = @"Walk the dog"; } else if (indexPath.row % 5 == 1) { label.text = @"Brush my teeth"; } else if (indexPath.row % 5 == 2) { label.text = @"Learn iOS development"; } else if (indexPath.row % 5 == 3) { label.text = @"Soccer practice"; } else if (indexPath.row % 5 == 4) label.text = @"Eat ice cream"; return cell; } - tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } // Control reaches end of non-function @end
- Как декодировать строку с использованием NSSecureCoding в Swift 3?
- В Xcode, как не запускать определенные сценарии создания сценариев запуска при запуске тестов?
- Подкласс XCTestCase приводит к невозможности загрузить базовый модуль XCTest
- ScrollView с функцией автоматической прокрутки
- Ошибка импорта отчета о сбое iOS в Xcode 6.1
- Xcode 5 сжимает каждый объект на Storyboard на 20px
- Вставить несколько контроллеров просмотра в контроллер навигации
- Сертификат распространения Enterprise Enterprise Developer появляется в цепочке ключей, а не в Xcode Organizer
В вашем примере вы не выделяете UITableViewCell
если ни один из них не был удален. Вам нужно сделать что-то вроде этого:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"]; if( cell == nil ) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ChecklistItem"] autorelease]; // whatever additional initialization ... }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UItableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UItableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } //write your code here return cell; }
Вы должны выделить UITableViewCell
в tableView: cellForRowAtIndexPath:
Ваш метод должен выглядеть следующим образом:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UItableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UItableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } //INSERT YOUR CODE }