开发者

Grouped Table View

New to Xcode, I have created a grouped table view,containing different amounts of rows in e开发者_运维百科ach section and I now do not know the best way to populate the cells with data then move on to the next view when the cell is pressed. Please Help. Thank you


you could try out this basic tutorial to see how you can populate your table.. http://blog.webscale.co.in/?p=150

and for performing action when a cell is pressed, you would basically need to do something like this in the didSelectRowAtIndexPath method

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

This is just a very very basic example of what you want to do... playing a bit around with this would help you learn more...


    **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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜