热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

TableView和Detail视图单元格显示-TableViewandDetailviewcelldisplay

ImlearninghowtomakeacontactusingTableViewandnavigationcontroller.Ihavedonethefirst

I'm learning how to make a contact using TableView and navigation controller. I have done the first view page with some cells, but I have some problem with showing the cells on the detail view page of each cell from first view. when tap the Group A, Group B, Group C on first view page, it goes to the detail view of each cell, it should show cells named A1 A2 A3, B1 B2 B3 or C1 C2 C3 according to my code on detail view page. but it display nothing. Hope someone can give me some advises, thank you so much!

我正在学习如何使用TableView和导航控制器进行联系。我已经完成了第一个包含一些单元格的视图页面,但是我在第一个视图中显示每个单元格的详细视图页面上的单元格时遇到了一些问题。当在第一个视图页面上点击A组,B组,C组时,它会进入每个单元格的详细视图,它应该根据详细视图页面上的代码显示名为A1 A2 A3,B1 B2 B3或C1 C2 C3的单元格。但它什么都没显示。希望有人能给我一些建议,非常感谢你!

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

first view

first view

detail view but nothing displayed

细节视图,但没有显示

detail view but nothing displayed

1 个解决方案

#1


0  

Have you set the delegate and datasource of tableview?

您是否设置了tableview的委托和数据源?

If Yes, check if the datasource methods (numberOfRowsInSection:) are called after you do

如果是,请检查是否在执行后调用了数据源方法(numberOfRowsInSection :)

groupA = [NSArray arrayWithObjects:@"A1",@"A2",@"A3",nil]; in viewDidLoad method.

groupA = [NSArray arrayWithObjects:@“A1”,@“A2”,@“A3”,nil];在viewDidLoad方法中。


推荐阅读
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了一个Java猜拳小游戏的代码,通过使用Scanner类获取用户输入的拳的数字,并随机生成计算机的拳,然后判断胜负。该游戏可以选择剪刀、石头、布三种拳,通过比较两者的拳来决定胜负。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了Java高并发程序设计中线程安全的概念与synchronized关键字的使用。通过一个计数器的例子,演示了多线程同时对变量进行累加操作时可能出现的问题。最终值会小于预期的原因是因为两个线程同时对变量进行写入时,其中一个线程的结果会覆盖另一个线程的结果。为了解决这个问题,可以使用synchronized关键字来保证线程安全。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • 本文介绍了brain的意思、读音、翻译、用法、发音、词组、同反义词等内容,以及脑新东方在线英语词典的相关信息。还包括了brain的词汇搭配、形容词和名词的用法,以及与brain相关的短语和词组。此外,还介绍了与brain相关的医学术语和智囊团等相关内容。 ... [详细]
  • SpringBoot uri统一权限管理的实现方法及步骤详解
    本文详细介绍了SpringBoot中实现uri统一权限管理的方法,包括表结构定义、自动统计URI并自动删除脏数据、程序启动加载等步骤。通过该方法可以提高系统的安全性,实现对系统任意接口的权限拦截验证。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
author-avatar
iar2984165
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有