Сгруппированный табличный вид - PullRequest
0 голосов
/ 23 марта 2011

Впервые в Xcode я создал сгруппированное табличное представление, содержащее различное количество строк в каждом разделе, и теперь я не знаю, как лучше всего заполнить ячейки данными, а затем перейти к следующему представлению при нажатии на ячейку.,Пожалуйста помоги.Спасибо

Ответы [ 2 ]

0 голосов
/ 12 декабря 2012
    **set in .h file**
    @property(nonatomic, retain)NSArray *data;
    @property(nonatomic, retain)NSArray *sections; 

    **in .m file view did load** 
        self.sections = [[NSArray alloc] initWithObjects:@"university",@"sabaragamuwa",@"Srilanka",nil];
        self.data = [[NSArray alloc]initWithObjects:
                     [[NSArray alloc] initWithObjects:
                      @"CiS",

                      @"006",
                      @"07", nil],
                     [[NSArray alloc] initWithObjects:
                      @"cis",
                      @"006",
                      @"007", nil],
                     [[NSArray alloc] initWithObjects:
                      @"cis",
                      @"006",
                      @"07", nil],nil];

    **addthoose**

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return [self.sections count];
    }
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
        return [self.sections objectAtIndex:section];
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    #warning Incomplete method implementation.
        // Return the number of rows in the section.
    return [data count];}


    **addalsooo**
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                                 SimpleTableIdentifier];

        // Configure the cell...

        if (cell == nil){
            // Create the cell.
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:SimpleTableIdentifier];
        }

        NSArray* dataArray = [data objectAtIndex:indexPath.section];
        cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment = UITextAlignmentRight;

        cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:139.0/255.0 blue:69.0/255.0 alpha:1.0];

        UIImage *cellImage = [UIImage imageNamed:@"oranimCellIco.png"];
        cell.imageView.image = cellImage;

        return cell;}

    }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray* dataArray = [data objectAtIndex:indexPath.section];
    NSString *catgory= [dataArray objectAtIndex:indexPath.row];
    if(catgory==@"cis")
    {



        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Answer Set"
                                                            message:@"Answer set as Yes Or No"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
        [alertView show];



 }
    else if(catgory==@"006")
    {

        answerviewcon *vc1=[self.storyboard instantiateViewControllerWithIdentifier:@"answerviewcon"];

        [self presentViewController:vc1 animated:YES completion:nil];

    }
0 голосов
/ 23 марта 2011

вы можете попробовать этот базовый учебник, чтобы увидеть, как вы можете заполнить свою таблицу .. http://blog.webscale.co.in/?p=150

и для выполнения действий, когда ячейка нажата, вам в основном нужно сделать что-то подобное вМетод didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if( 0 == indexPath.row)
{
    NSLog(@"first row selected");
if(patientView == nil)
    patientView = [[PatientList alloc]init];

[self.navigationController pushViewController:patientView animated:YES];
}

Это просто очень простой пример того, что вы хотите сделать ... немного поиграв с этим, вы сможете узнать больше ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...