-3

Im new in iphone and I want know that what can create tableview with many cell of object like this :

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

in tableview that when to click any cell fo on next page that is tableview with many object of first object (like this : lion 1,lion 2,lion 3,lion 4,lion 5,...)

so I want that create tableview in tableview another ...

please guide me. thanks!!!

janatan
  • 415
  • 2
  • 5
  • 11

3 Answers3

0

Use following table View's method

#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;
}

Below method is use for fire Action When you select row from 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];

}
iPatel
  • 46,010
  • 16
  • 115
  • 137
0

First of all , you need to set your tableview's datasource and delegate through your xib.

Now to return numberofrows in your tableview , there is one delegate method

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

here you can return animal.count; This will create 10 cells, if you have 10 objects in your array.

> 

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

This will return tableview with objects existing in your animal array. And after that to get selected row's detail , there is one method , didselectrowatindexpath . Try googling it. That's it .. ;)

iCoder
  • 1,298
  • 1
  • 9
  • 25
0

Please do better research before posting any questions here .May help you UITableView

lreddy
  • 449
  • 6
  • 19