我已經找到了這種解決方案,這是有用的。 這是我的代碼。
我有收集視圖。其中包含以下數組中的menuViewController的load方法。
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視圖控制器,顯示acording用戶選擇醫生的類別表視圖。
這裏是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];
}
}}
謝謝。
你使用故事板嗎? – engmahsa
爲tableview設置標籤,只需更改didselectRow上的標籤並重新載入表格即可 –
是的我正在使用故事板。 – Khushbu