我需要这方面的帮助。我已将 xcode 更新到最新版本,当我尝试进行测试时,旧代码会引发错误“类与键滚动视图的键值编码不兼容”。
有趣的是,这里没有滚动视图。我有其他视图几乎完全相同的代码,它工作正常。这是代码。也没有笔尖,因此从视图中取出滚动视图将不起作用。
#import "pearGalleryController.h"
#import "pearGallery.h"
@implementation pearGalleryController
- (void)viewDidLoad {
[超级视图DidLoad];
self.tableView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:100];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.navigationItem.title = @"各种梨";
}
- (void)didReceiveMemoryWarning {
// 如果没有超级视图,则释放视图。
[super didReceiveMemoryWarning];
// 释放所有未使用的缓存数据、图像等。
}
- (void)viewDidUnload {
}
#pragma mark 表格视图方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
返回 1;
}
// 自定义表格视图中的行数。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
返回 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
返回 122;
}
// 自定义表格视图单元格的外观。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
静态 NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(细胞 == 零){
// cell 是 UITableViewCell 的一个对象 这将一个对象分配给一个 cell 2 个内存区域,o 需要在 alloc 上自动释放,因为它是一个对象
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// 设置单元格...
int picIndex = [indexPath 行]*3;
UIButton* tempView = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 107,123)];
[tempView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"pears_%d.png",picIndex]]
forState:UIControlStateNormal];
tempView.tag = picIndex;
[tempView addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:tempView];
[临时视图发布];
tempView = [[UIButton alloc]initWithFrame:CGRectMake(106, 0, 107,123)];
[tempView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"pears_%d.png",picIndex+1]]
forState:UIControlStateNormal];
tempView.tag = picIndex+1;
[tempView addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:tempView];
[临时视图发布];
tempView = [[UIButton alloc]initWithFrame:CGRectMake(212, 0, 107,123)];
[tempView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"pears_%d.png",picIndex+2]]
forState:UIControlStateNormal];
tempView.tag = picIndex+2;
[tempView addTarget:self action:@selector(buttonClick:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:tempView];
[临时视图发布];
返回单元格;
}
-(void)buttonClick:(id)sender
{
UIButton* btn = (UIButton*)sender;
int 索引 = btn.tag;
pearGallery *anotherViewController = [[pearGallery alloc] initWithNibName:@"pearGallery" bundle:[NSBundle mainBundle]];
anotherViewController.myIndex = 索引;
[self.navigationController pushViewController:anotherViewController 动画:YES];
[另一个ViewController 版本];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
//UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"video.png"] style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[返回按钮释放];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (无效)dealloc {
[超级释放];
}
@结尾
和 h 文件
#进口
@interface pearGalleryController : UITableViewController {
}
@结尾