我在我的应用程序中使用了两个viewcontrollers。我的FirstViewController中有一个按钮。当我选择按钮时,它将推动SecondViewController。我在SecondViewController中有一个tableView。如何将SecondViewController的tableView中的选定索引的indexpath值传递给FirstViewController,而不使用NSUserDefaults?提前致谢。将indexpath值传递给FirstViewController
1
A
回答
2
0
使用NSNotifications传递值。
1
你总是可以从SecondViewController访问通过访问FirstViewController - [UIViewController中parentController]例如,如果FirstViewController有一个名为selectedRowInSecondController
属性:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstViewController *firstViewController = [self parentController];
firstViewController.selectedRowInSecondController = [indexPath row];
}
1
排在第二的ViewController在创建变量的财产。
@property(nonatomic,readwrite)NSUInteger indexValue;
然后
@synthesize indexValue= _indexValue;
然后创建secondVctr在firstviewcontroller的对象之后;
#import "secondViewcontroller.h"
@interface firstviewcontroller : UIViewController
@property(nonatomic,strong)secondViewcontroller *objsecondViewcontroller;
@synthesize objsecondViewcontroller =_objsecondViewcontroller;
将以下代码放入当用户敲击按钮时发生的事件。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CountDown *controller = [[secondvctr alloc] initWithNibName:@"secondvctr" bundle:nil];
self.objsecondViewcontroller.indexValue=indexPath
[self.navigationController pushViewController:controller animated:YES];
}
相关问题
- 1. 如何将SecondViewController的NSString值传递给FirstViewController?
- 2. 将NSString格式的数据从LoginViewController传递给FirstViewController
- 3. 如何将value从firstviewcontroller传递给xcode中的thirdview控制器?
- 4. 如何从performSegue()传递indexPath值prepareForSegue()
- 5. 将float值传递给glutBitmapString()?
- 6. 将值传递给节点
- 7. C++将值传递给fStream
- 8. 将值传递给代表
- 9. 将值传递给DetailViewController
- 10. 将值传递给指针
- 11. 将值传递给arraylist
- 12. 将价值传递给JLabel
- 13. Android将值传递给类
- 14. 将值传递给路由
- 15. 将ajax值传递给paypal
- 16. 将JavaScript值传递给PHP
- 17. 将值传递给partialview
- 18. 将值传递给SimpleModal
- 19. 将UISlider值传递给stringByEvaluatingJavaScriptFromString?
- 20. 将值传递给loadURL - Android
- 21. 将edittext值传递给gridview
- 22. 将值传递给jqplot
- 23. 将值传递给google.maps.LatLng
- 24. 将jQuery值传递给PHP
- 25. 将NSDictionary值传递给NSString
- 26. 将值传递给组件
- 27. 将值传递给yylex
- 28. 将值传递给_process_registration_details()
- 29. 将值传递给页面
- 30. 将值传递给函数