2011-03-23 64 views
0

新來的Xcode, 我創建了一個分組表視圖,含有不同量的行中的每個部分,我現在不知道該填充細胞的最佳方法與數據,然後移動到下一個時,視圖該單元格被按下。 請幫助。 謝謝分組表視圖

回答

0

,你可以嘗試一下這個基本教程,看你如何填充你的表.. 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]; 
} 

這僅僅是一個你想做的事非常非常簡單的例子......打了一下,這個周圍會幫助你瞭解更多...

0
**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([email protected]"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([email protected]"006") 
    { 

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

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

    }