0

私は本「Beginning iPhone 4 Development」のチュートリアルを行っており、第09章には次のコードスニペットがあります。

http://www.apress.com/downloadable/download/sample/sample_id/5/

#import "FirstLevelViewController.h"
#import "SecondLevelViewController.h"
#import "DisclosureButtonController.h"

@implementation FirstLevelViewController


@synthesize controllers;



-(void)viewDidLoad{

    self.title=@"First Level";  
    NSMutableArray * array = [[NSMutableArray alloc] init];

    //Disclosure Button 
    DisclosureButtonController *disclosureButtonController = [[DisclosureButtonController alloc]initWithStyle:UITableViewStylePlain];

    disclosureButtonController.title = @"Disclosure Buttons";
    disclosureButtonController.rowImage = [UIImage imageNamed:@"disclosureButtonControllerIcon.png"];
    [array addObject:disclosureButtonController];
    [disclosureButtonController release];

    self.controllers = array;
    [array release];
    [super viewDidLoad];

}


-(void)viewDidUnload{

    self.controllers = nil;
    [super viewDidUnload];
}


-(void)dealloc{
    [controllers release];
    [super dealloc];
}



#pragma mark -

#pragma mark Table Data Source Methods
-(NSInteger) tableView: (UITableView *)tableView
numberOfRowsInSection:(NSInteger)section{

    return [self.controllers count];

}


-(UITableViewCell *) tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *) indexPath{


    static NSString *FirstLevelCell = @"FirstLevelCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell]autorelease];
    }


    //configure the cell
    NSUInteger row = [indexPath row];
    DisclosureButtonController *controller = [controllers objectAtIndex:row];
    cell.textLabel.text=controller.title;
    cell.imageView.image = controller.rowImage;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;


}

#pragma mark - 
#pragma mark Table View Delegate Methods

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


    NSUInteger row = [indexPath row];

    SecondLevelViewController *nextController = [controllers objectAtIndex:row];
    [self.navigationController pushViewController:nextController animated:YES];


}



@end

最後の声明:

[self.navigationController pushViewController:nextController animated:YES];

基本的に同じ既存のコントローラーをプッシュしているため、私には意味がありません。ただし、アプリをコンパイルして実行すると、すべて正常に動作します。私の質問は、このアプリで次の画面に移動する方法を教えてください。

4

1 に答える 1

1

基本的に同じ既存のコントローラーをプッシュしているため、最後のステートメントは私には意味がありません。

同じ既存のコントローラーをプッシュしているのではなく、コントローラー配列から取得したnextControllerをプッシュしています。

nextController = [コントローラーobjectAtIndex:row];

[self.navigationController pushViewController: nextControllerアニメーション:YES];

于 2011-04-24T03:43:19.333 に答える