当我选择某个单元格时,它不会显示DetailViewController 那是来自DetailViewController.h的鳕鱼
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property(nonatomic,strong) NSString *imageName;
@property(nonatomic,strong) IBOutlet UIImageView *imageView;
@end
来自DetailViewController.m的Cod
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize imageName,imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
imageView.image=[UIImage imageNamed:imageName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
和ViewController.m` #import“ViewController.h” #import“DetailViewController.h”
@interface ViewController (){
NSArray *soundtitles;
NSArray *thumbs;
}
@end
@implementation ViewController
@synthesize tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// self.title=@"Точки";
soundtitles = [[NSArray alloc]initWithObjects:@"novaposhta",@"ac-2",@"vugovskogo",@"naykova ",@"iskra",nil];
thumbs=[[NSArray alloc]initWithObjects:@"thumbsnovaposhta.jpg",@"thumbsac-2.jpg",@"thumbvugovskogo.jpg",@"thumbnaykova.jpg",@"thumbsiskra.jpg", nil];
tableView.backgroundColor=[UIColor clearColor];
tableView.alpha=0.9;
}
#pragma mark -
#pragma mark Table view data source
-(NSInteger) numberofSectionInTableView:(UITableView*)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return [soundtitles count];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
}
cell.textLabel.text=[soundtitles objectAtIndex:indexPath.row];
cell.imageView.image=[UIImage imageNamed:[thumbs objectAtIndex:indexPath.row]];
cell.backgroundColor=[UIColor clearColor];
cell.textLabel.textColor= [UIColor whiteColor];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSString *selectedImage=[[NSString alloc]init];
switch (indexPath.row) {
case 0:
selectedImage=@"novaposhta.jpg";
break;
case 1:
selectedImage=@"ac-2.jpg";
break;
case 2:
selectedImage=@"vugovskogo.jpg";
break;
case 3:
selectedImage=@"naykova.jpg";
break;
case 4:
selectedImage=@"iskra.jpg";
break;
default:
break;
}
DetailViewController *detailScreen=[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
detailScreen.imageName=selectedImage;
[self.navigationController pushViewController:detailScreen animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我还添加了NavigatorController,但它没有帮助。
答案 0 :(得分:0)
如果你正确地复制了代码:
-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath
tableView
和didSelectRowAtIndexPath
答案 1 :(得分:0)
更正方法如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //你的代码}
而不是你的方法
- (无效)的tableView:(UITableView的*)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
你忘记添加空格检查两种方法