I am new to iPhone Development. I am trying to push a new table view at didSelectRowAtIndexPath of previous table.
我不明白应该使用什么逻辑。
这是我的代码。
- (void)viewDidLoad {
[super viewDidLoad];
dentalDoc = [[NSMutableArray alloc]initWithObjects:@"one ",@"two",@"Three", nil];
dentalDocImage = [[NSMutableArray alloc]initWithObjects:@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",nil];
searchDocList = [[NSMutableArray alloc]initWithObjects:@"Mary D'souza",@"Eric Josephson",@"Robert Adler",@"Lee Gold",@"Kevin Hansen",@"Karen Ziselman",@"Brad Gosky",@"Mark kogan",@"John Kong",@"Justin kohen",@"Oren Rehmanan",@"Paul Baker",@"Devashish Agarwal",@"Allen Chamberlin",@"Todd Lasner",@"Ryan walsh",@"steven Loan",@"Shrikant Mehta",@"Alexander lobo",nil];
doctorProfileImageList = [[NSMutableArray alloc]initWithObjects:@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",nil];}
和其他表视图方法。
- (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.
if (docsInt==0)
{
return [dentalDoc count];
}
else
{
return [searchDocList count];
}}
以及cellForRowAtIndexPath方法。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"cell";
SearchCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if(docsInt == 0)
{
cell.lblDocName.text = [dentalDoc objectAtIndex:indexPath.row];
cell.imgProfile.image = [UIImage imageNamed:[dentalDocImage objectAtIndex:indexPath.row]];
}
else
{
cell.lblDocName.text = [searchDocList objectAtIndex:indexPath.row];
cell.imgProfile.image = [UIImage imageNamed:[doctorProfileImageList objectAtIndex: indexPath.row]];
}
return cell;}
我正在尝试检索医生名单,例如Dentist,MBBS,BHMS。 选择类别后,我想检索按类别选择的医生姓名列表。
请尽快回复。
答案 0 :(得分:0)
如果您使用的是故事板,请使用以下代码
DetailViewController* detailViewController =
[self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewControllerID"];
if([self.navigationController respondsToSelector:@selector(showViewController:sender:)])
[self.navigationController showViewController:detailViewController sender:self];
else
[self.navigationController pushViewController:detailViewController animated:animated];
您也可以参考:uitableView didSelectRowAtIndexPath "selected row not loading the detail view"
希望这很有用
答案 1 :(得分:0)
我找到了解决方法。 这是我的代码。
我有收集视图。其中包含以下Arrays视图中的menuViewController的加载方法。
searchIcons = [NSArray arrayWithObjects:@"empty-filter-xl",@"icon_place",@"ProfilePicRound",@"green_heart_rate",@"MYP",@"Maps-icon", nil];
searchNames = [NSArray arrayWithObjects:@"Dentist",@"MBBS",@"Psychiatrist",@"Cardiologist",@"Nurologist",@"Orthopedic",nil];
这些是集合视图方法。
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return searchIcons.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
FilterCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.imgFilterIcon.image = [UIImage imageNamed:[searchIcons objectAtIndex:indexPath.row]];
cell.lblFilterCategory.text = [NSString stringWithFormat:@"%@",[searchNames objectAtIndex:indexPath.row]];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
SearchList *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardIdentifier"];
[self.navigationController pushViewController:svc animated:YES];
if ([[searchNames objectAtIndex:indexPath.row]isEqualToString:@"Dentist"])
{
svc.docsInt = 0;
}
else if([[searchNames objectAtIndex:indexPath.row]isEqualToString:@"MBBS"])
{
svc.docsInt = 1;
}
else if([[searchNames objectAtIndex:indexPath.row]isEqualToString:@"Psychiatrist"])
{
svc.docsInt = 2;
}
else
{
svc.docsInt = 3;
}
}
在didSelectItemAtIndexPath中,用户将推送到SearchList View Controller,该控制器显示用户选择医生类别的表格视图。
这是searchList视图控制器的代码。
根据医生的类别列出数组。在视图中执行加载方法。
dentalDoc = [[NSMutableArray alloc]initWithObjects:@"one ",@"two",@"Three", nil];
dentalDocImage = [[NSMutableArray alloc]initWithObjects:@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",nil];
mbbsDoc = [[NSMutableArray alloc]initWithObjects:@"MBBS 1",@"MBBS 2",@"MBBS 3",@"MBBS 4",@"MBBS 5",@"MBBS 6",@"MBBS 7", nil];
mbbsDocImage = [[NSMutableArray alloc]initWithObjects:@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon", nil];
PsychiatristDoc = [[NSMutableArray alloc]initWithObjects:@"Doctor 1",@"Doctroe 2",@"Doctor 3",@"Doctor 4",@"Doctor 5", nil];
PsychiatristDocImage = [[NSMutableArray alloc]initWithObjects:@"empty-filter-xl",@"icon_place",@"ProfilePicRound",@"green_heart_rate",@"MYP",nil];
searchDocList = [[NSMutableArray alloc]initWithObjects:@"Mary D'souza",@"Eric Josephson",@"Robert Adler",@"Lee Gold",@"Kevin Hansen",@"Karen Ziselman",@"Brad Gosky",@"Mark kogan",@"John Kong",@"Justin kohen",@"Oren Rehmanan",@"Paul Baker",@"Devashish Agarwal",@"Allen Chamberlin",@"Todd Lasner",@"Ryan walsh",@"steven Loan",@"Shrikant Mehta",@"Alexander lobo",nil];
doctorProfileImageList = [[NSMutableArray alloc]initWithObjects:@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",@"ProfilePicRound",@"MapiCon",nil];
这是表视图方法。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
if (docsInt==0)
{
return [dentalDoc count];
}
if (docsInt==1)
{
return [mbbsDoc count];
}
if (docsInt == 2){
return [PsychiatristDoc count];}
else
{
(docsInt == 3);
return [searchDocList count];
}}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"cell";
SearchCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if(docsInt == 0)
{
cell.lblDocName.text = [dentalDoc objectAtIndex:indexPath.row];
cell.imgProfile.image = [UIImage imageNamed:[dentalDocImage objectAtIndex:indexPath.row]];
}
else if (docsInt == 1)
{
cell.lblDocName.text = [mbbsDoc objectAtIndex:indexPath.row];
cell.imgProfile.image = [UIImage imageNamed:[mbbsDocImage objectAtIndex:indexPath.row]];
}
else if(docsInt == 2)
{
cell.lblDocName.text = [PsychiatristDoc objectAtIndex:indexPath.row];
cell.imgProfile.image = [UIImage imageNamed:[PsychiatristDocImage objectAtIndex:indexPath.row]];
}
else
{
cell.lblDocName.text = [searchDocList objectAtIndex:indexPath.row];
cell.imgProfile.image = [UIImage imageNamed:[doctorProfileImageList objectAtIndex: indexPath.row]];
}
return cell;}
最后但并非最不重要的导航方法。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([segue.identifier isEqualToString:@"Detail"])
{
NSIndexPath *indexpath = [tblList indexPathForSelectedRow];
DoctorProfile *destViewController = segue.destinationViewController;
//destViewController.doctorName = [
if (docsInt == 0)
{
destViewController.doctorName = [dentalDoc objectAtIndex:indexpath.row];
}
if (docsInt == 1)
{
destViewController.doctorName = [mbbsDoc objectAtIndex:indexpath.row];
}
if (docsInt == 2)
{
destViewController.doctorName = [PsychiatristDoc objectAtIndex:indexpath.row];
}
else
{
destViewController.doctorName = [searchDocList objectAtIndex:indexpath.row];
}
}}
谢谢。