У меня возникла проблема с вызовом метода didselectrowatindexpath. Мой TableView устанавливается в viewdidload следующим образом:didselectrowatindexpath не вызван
- (void)viewDidLoad
{
//[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView reloadData];
self.detailViewController = (klViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}
Теперь мой cellForRowAtIndexPath вызывается и я повторно использовать клетки следующим образом:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"menuSelection1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
AmbassadorInfoData * data = [self.LoadMenuItems objectAtIndex:indexPath.row];
cell.textLabel.text = data.treeName;
return cell;
}
Я проверил другие ответы, и в основном сказал, что может быть может использоваться использование didDeselectRowAtIndexPath. Но здесь это не так. Теперь моя проблема заключается в моем контроллере разделенного представления всякий раз, когда я выбираю любую опцию, соответствующее подробное представление не отображается и пустое. Ни один из моих методов в контроллере rootview (klViewController) не вызван. Что может быть причиной этого? Ниже перечислены все методы, связанные с UITableView. Он реализуется в том же классе, что и в viewDidLoad
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.LoadMenuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"menuSelection1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
AmbassadorInfoData * data = [self.LoadMenuItems objectAtIndex:indexPath.row];
cell.textLabel.text = data.treeName;
return cell;
}
-(NSArray *)LoadMenuItems
{
NSMutableArray * menuData = [[NSMutableArray alloc] initWithCapacity:5];
AmbassadorInfoData * data = [[AmbassadorInfoData alloc] init];
data.treeName = @"Ambassador Info";
data.treeDescription = @"This is temp data.";
NSString * file = [[NSBundle mainBundle] pathForResource:@"oak" ofType:@"jpg"];
data.treePhoto = [UIImage imageWithContentsOfFile:file];
[menuData addObject:data];
data=nil;
data = [[AmbassadorInfoData alloc] init];
data.treeName = @"AmbassadorInternalList";
data.treeDescription = @"This is temp data.).";
file = [[NSBundle mainBundle] pathForResource:@"DouglasFir" ofType:@"jpg"];
data.treePhoto = [UIImage imageWithContentsOfFile:file];
[menuData addObject:data];
data=nil;
data = [[AmbassadorInfoData alloc] init];
data.treeName = @"Text 3";
data.treeDescription = @"This is temp data.";
file = [[NSBundle mainBundle] pathForResource:@"SugarMaple" ofType:@"jpg"];
data.treePhoto = [UIImage imageWithContentsOfFile:file];
[menuData addObject:data];
data=nil;
data = [[AmbassadorInfoData alloc] init];
data.treeName = @"Text 4";
data.treeDescription = @"This is temp data.";
file = [[NSBundle mainBundle] pathForResource:@"RedMaple" ofType:@"jpg"];
data.treePhoto = [UIImage imageWithContentsOfFile:file];
[menuData addObject:data];
data=nil;
data = [[AmbassadorInfoData alloc] init];
data.treeName = @"Text 5";
data.treeDescription = @"This is temp data.";
file = [[NSBundle mainBundle] pathForResource:@"Pine" ofType:@"jpg"];
data.treePhoto = [UIImage imageWithContentsOfFile:file];
[menuData addObject:data];
menuItems = [[NSArray alloc] initWithArray:(NSArray *)menuData];
data=nil;
return menuItems;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AmbassadorInfoData * selectedItem =(AmbassadorInfoData *)[self.menuItems objectAtIndex:[self.tableView indexPathForSelectedRow].row];
detailObject = selectedItem;
[detailViewController setDetailItem:detailObject];
}
@end
Я думаю, что вы не установили делегата –
покажите все ваши методы, связанные с UITableView. @ Vinu1991, см. Его метод viewDidLoad. – Tirth
Почему ваш [super viewDidLoad] закомментирован? вы сохраняете все свои методы UITableViewDelegate в том же классе (не KLViewController?) –