-3

我是 iphone 的新手,我想知道什么可以创建具有多个对象单元格的 tableview,如下所示:

NSMutableArray *animal = [[NSMutableArray alloc]initWithObjects:@"Lion",@"Tiger",@"Dog",@"Cat",@"Sheep",@"Wolf", nil];

在 tableview 中,何时单击下一页上的任何单元格 fo,该单元格是具有第一个对象的许多对象的 tableview(例如:lion 1,lion 2,lion 3,lion 4,lion 5,...)

所以我希望在另一个 tableview 中创建 tableview ...

请指导我。谢谢!!!

4

3 回答 3

0

使用下表View的方法

#pragma mark -
#pragma mark TableView data source

- (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.
        return animal.count;
    }


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

     cell.textLabel.text = [array objectAtIdex:indexPath.row];

    return cell;
}

当您从 UITableView 中选择行时,以下方法用于触发动作。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
         // Create Object of you SecondViewController for go on.
     SecondViewController *tlController = [[SecondViewController alloc] init];
     tlController.animalName = [array objectAtIndex:insexpath.row];// here you need to pass name of animal on SecondViewController, and in SecondViewController you need to display animal name related to pass from previous view controller.

     [self.navigationController pushViewController:tlController animated:YES];

}
于 2013-04-15T10:14:14.437 回答
0

首先,您需要通过 xib 设置 tableview 的数据源和委托。

现在要返回 tableview 中的 numberofrows ,有一个委托方法

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { }

在这里你可以返回animal.count;如果数组中有 10 个对象,这将创建 10 个单元格。

> 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  UITableViewCell
    *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
         if (cell == nil) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyIdentifier"] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }

        cell.textLabel.text = [animal objectatIndex:indexpath.ro];
        return cell;
}

这将返回您的动物数组中存在的对象的表格视图。之后要获取所选行的详细信息,有一种方法 didselectrowatindexpath 。尝试用谷歌搜索它。而已 .. ;)

于 2013-04-15T10:19:58.570 回答
0

请在此处发布任何问题之前进行更好的研究。可能对您UITableView有所帮助

于 2013-04-15T10:26:14.683 回答