[英]Xcode 5 iOS 7 TableView with DetailViewController
When I choose some cell it doesn't show DetailViewController That's cod from DetailViewController.h 当我选择一些单元格时,它不显示DetailViewController那是来自DetailViewController.h的编码
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property(nonatomic,strong) NSString *imageName;
@property(nonatomic,strong) IBOutlet UIImageView *imageView;
@end
Cod from DetailViewController.m 来自DetailViewController.m的鳕鱼
#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
And ViewController.m` #import "ViewController.h" #import "DetailViewController.h" 和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
Also i added NavigatorController, but it didn't help. 我也添加了NavigatorController,但没有帮助。
if you copied code properly the reason in: 如果您正确复制了代码,则原因如下:
-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath
there must be space between tableView
and didSelectRowAtIndexPath
tableView
和didSelectRowAtIndexPath
之间必须有空间
Correct the method as below: 纠正方法如下:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // your code }
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {//您的代码}
Instead of your method 代替你的方法
-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath
-(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
you just forget to add space check both methods 您只是忘记添加空间检查这两种方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.