Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 表视图的基本功能和外观与MS Excel类似_Iphone_Objective C_Cocoa Touch_Uitableview - Fatal编程技术网

Iphone 表视图的基本功能和外观与MS Excel类似

Iphone 表视图的基本功能和外观与MS Excel类似,iphone,objective-c,cocoa-touch,uitableview,Iphone,Objective C,Cocoa Touch,Uitableview,我不熟悉Objective-C编程。请帮助我了解如何将数据插入具有类似于MS Excel的视觉样式的表视图。它不能完全像您希望的那样,因为MS Excel和iPhone上的表是不同的 iOS上的表视图有两个项,您可以配置它们来显示数据——一个数据源和一个委托 如果您可以从MS Excel中获取所有数据,只需知道其行和列即可访问任何特定数据,那么这些数据就可以显示在表视图中 在表视图中有一个nsindepath的概念,它是行号和相应节号的结构。 现在让我们假设您的Excel文档有100个学生的记录

我不熟悉Objective-C编程。请帮助我了解如何将数据插入具有类似于MS Excel的视觉样式的表视图。

它不能完全像您希望的那样,因为MS Excel和iPhone上的表是不同的

iOS上的表视图有两个项,您可以配置它们来显示数据——一个数据源和一个委托

如果您可以从MS Excel中获取所有数据,只需知道其行和列即可访问任何特定数据,那么这些数据就可以显示在表视图中

在表视图中有一个
nsindepath
的概念,它是行号和相应节号的结构。 现在让我们假设您的Excel文档有100个学生的记录,每个记录有三个字段:姓名、年龄、性别。在这种情况下,您将创建一个表视图,其中有一百个部分,每个部分有三行

现在假设您有一个名为
myViewController
的视图控制器来显示这个名为
myTableView
的表视图:

-(void)viewDidLoad {

    myTableView.datasource = self; 
    myTableView.delegate = self;
}
现在,在执行此操作之前,需要在MyViewController.h文件中执行以下操作

@interface MyViewController: UIViewController <UITableViewDataSource, UITableViewDelegate> {
现在需要实现表视图数据源和委托方法:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [allStudents count];
}

-(NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section 
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
        cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    Student * current = [allStudents objectAtIndex:NSIndexPath.section];
    cell.textLabel.text = current.name;
    if( current.male ) {
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%dyr M",current.age];
    } else {
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%dyr F",current.age];
    }


    return cell;
}
您可以访问表视图的不同属性,使其行为不同


我希望这对您有所帮助。

amit感谢您提供此代码。但我对学生*当前有一个疑问。请给我回复。再次感谢您提供回复。当我访问此代码时,我收到此错误“未知'部分'类方法”你能不能给我一些纠正这个错误的指导。请给我一些建议。写答案时请使用大男孩的语言。输入完整的单词“you”而不是“u”。只剩下两个字了。这并不难,Student是一个演示类,有三个属性,即NSString*name;整数*年龄;布尔男性;//如果性别为男性,则为“是”,否则为“否”,您将收到该错误,因为m代码中存在错误,而不是Student*current=[allStudents objectAtIndex:NSIndexPath.section];write Student*current=[allStudents objectAtIndex:indexPath.section]@格雷代码:什么时候开始编码大男孩的生意了?我遇到的最后一批程序员是《星球大战》和《星际迷航》的粉丝,他们玩纸笔RPG游戏,让妈妈帮他们洗衣服。这不是真正的“大男孩”。
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [allStudents count];
}

-(NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section 
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
        cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    Student * current = [allStudents objectAtIndex:NSIndexPath.section];
    cell.textLabel.text = current.name;
    if( current.male ) {
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%dyr M",current.age];
    } else {
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%dyr F",current.age];
    }


    return cell;
}