Iphone 如何定义uitableviewcells

Iphone 如何定义uitableviewcells,iphone,ios,uitableview,Iphone,Ios,Uitableview,我正在创建一个uitableview,它有两个部分,部分==0有5行,部分==1有1行 我还声明了objective-c类中的几个函数,我想将它们挂接到五行中的每一行。然而,我不知道如何实现这一点 我想这是一种 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @

我正在创建一个uitableview,它有两个部分,部分==0有5行,部分==1有1行

我还声明了objective-c类中的几个函数,我想将它们挂接到五行中的每一行。然而,我不知道如何实现这一点

我想这是一种

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

    // Configure the cell...
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

//---------- In here put a bunch of IF statments, declaring each cell? and linking it to
//---------- the function I have declared in the objective-c class

    return cell;
}

通常,此函数将通过从数组、数据库或某些其他索引集合中提取数据来配置单元格:

if ([indexPath section] == 0) {
    [[cell textLabel] setText:[sectionOneValues objectAtIndex:[indexPath row]]];
}
else if ([indexPath section] == 0) {
    [[cell textLabel] setText:[sectionTwoValues objectAtIndex:[indexPath row]]];
}

在您的例子中,听起来您想“钩住”第0节中的5行的其他一些函数,因此除了在if子句中使用sectionValues数组之外,您还需要做其他事情。在不知道如何使用这些挂接的函数的情况下,更具体地说有点困难。

通常,此函数将通过从数组、数据库或某些其他索引集合中提取数据来配置单元格:

if ([indexPath section] == 0) {
    [[cell textLabel] setText:[sectionOneValues objectAtIndex:[indexPath row]]];
}
else if ([indexPath section] == 0) {
    [[cell textLabel] setText:[sectionTwoValues objectAtIndex:[indexPath row]]];
}

在您的例子中,听起来您想“钩住”第0节中的5行的其他一些函数,因此除了在if子句中使用sectionValues数组之外,您还需要做其他事情。如果不知道这些函数的作用是什么,就很难说得更具体一些。

视情况而定,所有单元格都是相等的,只是改变了它们的内容吗?那样的话,你是对的


另一方面,如果您计划在单元格中添加更多标签、图像或诸如此类的内容,那么对于每个不同的行,您必须调整创建单元格的方式,因此,必须添加新的单元格标识符以避免混合单元格,并更改
if(cell==nil){
来配置每个单元格设计。

取决于,所有单元格是否相等,但仅更改其内容?那样的话,你是对的


另一方面,如果您计划在单元格中添加更多标签、图像或诸如此类的内容,那么对于每个不同的行,您必须调整创建单元格的方式,因此,必须添加新的单元格标识符以避免混合单元格,并更改
if(cell==nil){
配置每个单元格设计。

通常在
表格视图中设置单元格:cellForRowAtIndexPath:
。在点击单元格时确定调用的函数通常在
表视图:didselectrowatinexpath
中完成

tableView:cellforrowatinexpath:
中设置单元格时,可以使用
indepath
指定节和行,如下所示:

if(indexPath.section == 0){

    if(indexPath.row == 0){

        // setup this cell...

    }else if(indexPath.row == 1){

    }// ...

}else if(indexPath.section == 1){

    if(indexPath.row == 0){

    }else if(indexPath.row == 1){

    }// ...
}

在确定用户点击每个单元格时调用哪个函数时,请在
tableView:didSelectRowAtIndexPath
中执行类似操作。可以找到Apple的相关文档。

通常,单元格是在
表格视图中设置的:cellForRowAtIndexPath:
。在点击单元格时确定调用的函数通常在
表视图:didselectrowatinexpath
中完成

tableView:cellforrowatinexpath:
中设置单元格时,可以使用
indepath
指定节和行,如下所示:

if(indexPath.section == 0){

    if(indexPath.row == 0){

        // setup this cell...

    }else if(indexPath.row == 1){

    }// ...

}else if(indexPath.section == 1){

    if(indexPath.row == 0){

    }else if(indexPath.row == 1){

    }// ...
}

在确定用户点击每个单元格时调用哪个函数时,请在
tableView:didSelectRowAtIndexPath
中执行类似操作。可以找到苹果公司的相关文档。

每个单元格都需要搜索数据库查询。但是每个单元格都将打开一个新的tableview,其中包含一系列可供选择的选项。。我只是想弄明白怎么做。。我以为我脑子里有这个,但今天坐在电脑前,我的脑子一片空白。苹果的示例代码通常在开始时非常有用。每个单元格搜索都需要一个数据库查询。但是每个单元格都将打开一个新的tableview,其中包含一系列可供选择的选项。。我只是想弄明白怎么做。。我本以为我脑子里有它,但今天坐在电脑前,我的脑子一片空白。苹果的示例代码通常在开始时非常有用。尝试使用
enum
,它有助于可读性。这样,如果单元格是静态的,您可以执行类似于
indexath.row=MyTableViewRowFruit
indexPath.row=MyTableViewSectionResults
的操作,尝试使用
enum
,这有助于提高可读性。这样,如果单元格是静态的,您可以执行类似于
indexPath.row=MyTableViewRowFruit
indexPath.row=MyTableViewSectionResults