2016-03-21 26 views
0

Masaüstünü ve gezinme denetleyicisini kullanarak nasıl bir iletişim kurabileceğimi öğreniyorum. İlk görüntü sayfasını bazı hücrelerle yaptım, ancak ilk hücreden her hücrenin ayrıntı görünümü sayfasındaki hücreleri gösterme konusunda bir sorunum var. Grup A, Grup B, Grup C'deki ilk görünüm sayfasına dokunduğunuzda, her hücrenin detay görünümüne gider, ayrıntı görünümündeki koduma göre A1 A2 A3, B1 B2 B3 veya C1 C2 C3 hücrelerini göstermelidir sayfa. ama hiçbir şey göstermiyor. Birisi bana bazı tavsiyelerde bulunabilir umuyoruz, çok teşekkür ederim!Tablo Görünümü ve Ayrıntı görünümü hücre ekranı

FirstViewController.m

@implementation FirstViewController 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSections(NSInteger)section{ 

    return [self.contactArray count]; 
} 

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *Celldentifier = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Celldentifier]; 

if (cell == NULL) { 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Celldentifier]; 

} 
cell.textLabel.text = [self.contactArray objectAtIndex:indexPath.row]; 
return cell; 

} 

-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    self.myTableView = [self.contactArray objectAtIndex:indexPath.row]; 
    [self performSegueWithIdentifier:@"To Second View Segue" sender:self];  
} 


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
    if([segue.identifier isEqualToString:@"To the second view"]){ 
     NSIndexPath *indexpath = [self.myTableView indexPathForSelectedRow]; 
     self.contactArray = [self.contactArray objectAtIndex:indexpath.row]; 
     SecondViewController *vc = segue.destinationViewController; 
     vc.memberName = [self.contactArray objectAtIndex:indexpath.row]; 
     vc.title = vc.memberName; 

    } 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.contactArray = [[NSMutableArray alloc]initWithObjects:@"Group A",@"Group B",@"Group C", nil]; 

} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

@end 

SecondViewController.m

@implementation SecondViewController{ 

NSArray *groupA; 
NSArray *groupB; 
NSArray *groupC; 

} 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 

    if([self.memberName isEqualToString:@"groupA"]){ 
     return [groupA count]; 
    } 
    else if([self.memberName isEqualToString:@"groupB"]){ 
     return [groupB count]; 
    } 
    else if([self.memberName isEqualToString:@"groupC"]){ 
     return [groupC count]; 
    } 
    return 0; 
} 

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *Celldentifier = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Celldentifier]; 

    if (cell == NULL) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Celldentifier]; 

    } 
    if([self.memberName isEqualToString:@"groupA"]){ 
     cell.textLabel.text = [groupA objectAtIndex:indexPath.row]; 
    } 
    if([self.memberName isEqualToString:@"groupB"]){ 
     cell.textLabel.text = [groupB objectAtIndex:indexPath.row]; 
    } 
    if([self.memberName isEqualToString:@"groupC"]){ 
     cell.textLabel.text = [groupC objectAtIndex:indexPath.row]; 
    } 

    return cell; 

} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    groupA = [NSArray arrayWithObjects:@"A1",@"A2",@"A3",nil]; 
    groupB = [NSArray arrayWithObjects:@"B1",@"B2",@"B3",nil]; 
    groupC = [NSArray arrayWithObjects:@"C1",@"C2",@"C3",nil]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

@end 

ilk görünüm

first view

ayrıntılı görünüm ama hiçbir şey

görüntülenen

detail view but nothing displayed

+0

Ne tür bir sorun yaşıyorsunuz? Sorununuz hakkında net ve spesifik olun. – rmaddy

+0

Grup A, Grup B, İlk Görünüm sayfasında C Grubu'na dokunduğunuzda, her hücrenin ayrıntı görünümüne gider, ayrıntıdaki koduma göre A1 A2 A3, B1 B2 B3 veya C1 C2 C3 hücrelerini göstermelidir sayfaya bak. ama hiçbir şey göstermiyor. Kötü ingilizcem için özür dilerim. – yucheng

cevap

0

Tablo görünümünün temsilci ve veri kaynağını ayarladınız mı?

Evet veri kaynağı yöntemleri (numberOfRowsInSection :) yapmak isimlendirildikleri kontrol durumunda

Grup A = [NSArray arrayWithObjects: "A3" @ "A2" @ "A1", @ nil]; viewDidLoad yönteminde.

İlgili konular