2015-10-13 28 views
0
I am new to iPhone Development. I am trying to push a new table view at didSelectRowAtIndexPath of previous table. 

我不明白什麼邏輯應該工作。如何在didselectrowatindexpath上推送新的表格視圖?

這是我的代碼。

- (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;} 

我想檢索醫生名單,例如牙醫,MBBS,BHMS。 選擇類別後我想檢索按類別選擇的醫生名稱列表表格。

請儘快回覆。

+0

你使用故事板嗎? – engmahsa

+0

爲tableview設置標籤,只需更改didselectRow上的標籤並重新載入表格即可 –

+0

是的我正在使用故事板。 – Khushbu

回答

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"

希望

+0

pushViewController成功運行。 searchListController也會出現。但它只顯示牙醫相關的數據。不是其他類別的數據。 – Khushbu

+0

你可以請你分享你的項目在ZIP和郵件給我,我會檢查它 – IamAnil

+0

我找到解決方案,請檢查下面。 – Khushbu

0

我已經找到了這種解決方案,這是有用的。 這是我的代碼。

我有收集視圖。其中包含以下數組中的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]; 
    } 


}} 

謝謝。

相關問題