开发者

iPhone: How to get each item in an array (for UITableview) to "link" to another table view

I have a table on my iPhone application. It works—it gets data from an array and 开发者_StackOverflow中文版displays it on the application. I now want to be able to add some navigation functionality to each item of the array (i.e. each item on the table).

How would I do this? My current Objective-C for the array:

- (void)viewDidLoad {
arryClientSide = [[NSArray alloc] initWithObjects:@"CSS", @"HTML", @"JavaScript", @"XML", nil];
arryServerSide = [[NSArray alloc] initWithObjects:@"Apache", @"PHP", @"SQL", nil];
self.title = @"Select a Language";
[super viewDidLoad];
}

Any help is greatly appreciated.


You need to implement the table view delegate method

tableView:didDeselectRowAtIndexPath:

so that each time a user selects a row by touching it the code within this method is executed. here you simply instantiate another view controller in charge of handling the item associated to the selected row/section and push it on the navigation stack, such as

 DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
 // ...
 // Pass the selected object to the new view controller.
 detailViewController.language = [arryClientSide objectAtIndex:indexPath.row];
 [self.navigationController pushViewController:detailViewController animated:YES];
 [detailViewController release];


you need to implement UITableView's

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

Method inside that

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(indexPath.row==0)
    {
        //some action
    }
    else if(indexPath.row==1)
    {
        //some action
    }

    else if(indexPath.row==2)
    {
        //some action
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜