0
A
回答
3
做到這一點,這將工作在你的情況下完美..
在你的第一個ViewController.h創建一個屬性來indexPath存儲
@property (nonatomic,strong) NSIndexPath *indexPath;
在你的第二個ViewController.h創建一個屬性來存儲indexPath
@property (nonatomic,strong) NSIndexPath *indexPath;
現在,在你第一次ViewController.m文件
忘記IBAction爲現在,在您的cellForRow寫這個選擇
[cell.btnOnCell addTarget:self action:@selector(btnAction:event:) forControlEvents:UIControlEventTouchUpInside];
寫這個方法
-(IBAction)btnAction: (UIButton *)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tblView];
self.indexPath = [self.tblView indexPathForRowAtPoint:currentTouchPosition];
NSLog(@"%li",(long)self.indexPath.row);
[self performSegueWithIdentifier:@"segueIdToYourSecondVC" sender:self];
}
沒有寫這個方法(您performSegueWithIdentifier後,該方法將調用)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segueIdToYourSecondVC"])
{
// Get reference to the destination view controller
YourSecondViewController *vc = [segue destinationViewController];
vc.indexPath=self.indexPath;
}
}
謝謝..希望對你有幫助。
+0
我不喜歡以編程方式調用像'performSegueWithIdentifier'這樣的函數,並且喜歡通過故事板 – FrozenHeart 2014-12-04 10:34:30
相關問題
- 1. 的UIButton和IBAction爲
- 2. IBAction爲的UIButton和EXC_BAD_ACCESS
- 3. UIButton的IBAction錯誤
- 4. 帶IBAction的IOS UIButton
- 5. UIButton觸發Segue
- 6. Segue TableViewCell與UIButton
- 7. Swift - IBACTION如何執行segue
- 8. 的UIButton的UIImage需要設置層順序z順序和z索引
- 9. 隱藏UIButton作爲IBAction
- 10. 的UITableViewCell和IBAction爲
- 11. 代表和IBAction
- 12. ios swift:@IBAction處理以避免segue
- 13. 不能UIButton的連接到IBAction爲
- 14. Segue和NSString Bug
- 15. 爲什麼我的UIButton segue的行爲不像UITableViewCell segue?
- 16. UIButton觸及IBAction,導致EXC_BAD_ACCESS與ARC
- 17. 從IBAction以編程方式添加UIButton
- 18. 在IBAction中將UIVIew與UIButton相關聯
- 19. 自定義UIButton - IBAction不工作
- 20. QGraphicsItem和Tab順序
- 21. group_concat sqlite和順序
- 22. awakeFromNib,applicationWillFinishLaunching和applicationDidFinishLaunching的順序?
- 23. tech_array和bio_array的順序
- 24. after_create和after_save的順序
- 25. iPhone開發 - IBAction爲和@property
- 26. 單個IBAction爲IBOutlet中和
- 27. XCode IBAction和IBOutlets錯誤
- 28. 與境界prepareForSeque和IBAction爲
- 29. Xcode IBAction和輸出口
- 30. iboutlet和ibaction連接錯誤
我認爲是的,但在某個地方並不清楚,但你想做什麼? – hoya21 2014-12-04 10:24:32