gpt4 book ai didi

iphone - 这个pushViewController语句在我正在做的教程中如何工作?

转载 作者:行者123 更新时间:2023-11-29 05:04:59 25 4
gpt4 key购买 nike

我正在做《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];

对我来说没有意义,因为本质上你是在插入相同的现有 Controller 。但是,当我编译应用程序并运行时,一切正常。我的问题是这个应用程序如何允许我进入下一个屏幕?

最佳答案

The very last statement makes no sense to me because essentially you are pushing the same existing controller.

您推送的不是同一个现有 Controller ,而是推送的 nextController,它来自 controllers 数组:

nextController = [controllers objectAtIndex:row];

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

关于iphone - 这个pushViewController语句在我正在做的教程中如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5768467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com