Merhaba,
Storyboard üzerinde doğru şekilde linklediniz mi? TableView'in cell'i seçiliyken kontrol tuşuna basılı tutup bir sonraki view'i işaretlerseniz didSelect metodu tetiklenmiş olur, siz de içerisinde istediginizi yapabilirsiniz. TableView'in delegate ve datasource bağlantılarını kontrol edin.
Alternatif bir çözüm;
ViewController.h
[code]
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
NSArray *myArray;
SecondViewController *secondViewController;
}
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@end
[/code]
ViewController.m
[code]
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
myArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"MyCell";
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.textLabel.text = myArray[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
secondViewController.labelText = myArray[indexPath.row];
[self presentViewController:secondViewController animated:YES completion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [myArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
@end
[/code]
SecondViewController.h
[code]
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
@property (strong, nonatomic) NSString *labelText;
@end
[/code]
SecondViewController.m
[code]
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_myLabel.text = _labelText;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
[/code]
*Storyboard üzerinden ID vermeyi unutmayın.
İyi çalışmalar.