2017-08-15 5 views
-3

私は2つのviewController、ViewControllerとTableViewControllerがあります。 ViewControllerにはボタンがあり、押すとTableViewControllerが起動します。 TableViewContollerには5つの行が含まれています。どのようにテーブルビュー内のリンク行をセグに

私がしようとしているのは、偶数行だけを押すとViewControllerに戻るべきです。この問題を解決するために、unwindSegueを使用することができますが、テーブル内の偶数行にsegueが応答する方法はわかりません。

#import "TableViewController.h" 

@interface TableViewController() 

@property NSArray *tableData; 

@end 

@implementation TableViewController 

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 

self.tableData = [NSArray arrayWithObjects:@"Android", 
        @"iOS", 
        @"swift", 
        @"objective-c", 
        @"openCV",nil]; 
} 

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 


-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection: 
(NSInteger)section { 

return [self.tableData count]; 
} 

-(UITableViewCell *) tableView:(UITableView *)tableView  
cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *simpleTableIdentifier = @"SimpleTableItem"; 

UITableViewCell *cell = [tableView 
dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] 
initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:simpleTableIdentifier]; 
} 

cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row]; 
cell.imageView.image = [UIImage imageNamed:@"images.jpg"]; 

return cell; 
} 

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath: 
(NSIndexPath *)indexPath { 

NSLog(@"%li", indexPath.row); 
NSLog(@"%@", [self.tableData objectAtIndex:indexPath.row]); 

} 

@end 
+0

あなたが呼び出すことができます。私はセグエ以下

にリンクされているテーブルの行を作成する方法を教えてください

はTableViewController

のコード

コードですperformSegueWithIdentifier didSelectRowAtIndexPath –

+0

@ReinierMelianで、テーブルビューを終了アイコンにリンクしてunを作成することはできませんwindsegue – user2121

+0

あなたのViewControllerとあなたのdestinationViewControllerの間のセグを作り、識別子を入れて –

答えて

-1
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath: 
(NSIndexPath *)indexPath { 
    if(indexPath.row % 2 == 0) { 
     // Even row... 
    } 

} 
関連する問題