简体   繁体   English

UITableViewController文件的位置

[英]Location of UITableViewController files

I have multiple tableviews that have various static cells and everything is cool. 我有多个具有各种静态单元格的表视图,并且一切都很酷。

I would like to implement some functionality to a button that is in one of the cells in all of the tables, but I do not know where the header and implementation files for UITableViewController are located and or how to access them. 我想为所有表的单元格之一中的按钮实现一些功能,但是我不知道UITableViewController的头文件和实现文件位于何处以及如何访问它们。 Any ideas? 有任何想法吗?

You can't directly manipulate UITableViewController . 您不能直接操纵UITableViewController Besides, it is not a good idea to do it anyway. 此外,无论如何也不是一个好主意。 The best way to do it is subclassing it. 最好的方法是将其子类化。

  1. Command+N and create a new NSObject file Command + N并创建一个新的NSObject文件
  2. When prompted, name it whatever you like (eg MyTableViewController ) 出现提示时, MyTableViewController命名(例如MyTableViewController
  3. Click on MyTableViewController.h in left side pane, and change NSObject to UITableViewController . 单击左侧窗格中的MyTableViewController.h ,然后将NSObject更改为UITableViewController
  4. Goto the XIB file or the Storyboard (whichever you are using) and change the class of your UITableViewController to MyTableViewController . 转到XIB文件或情节提要(无论使用哪种方式),然后将UITableViewController的类更改为MyTableViewController
  5. Give a number to the button's tag field (eg 1001). 在按钮的tag字段中输入一个数字(例如1001)。
  6. Now, in your MyTableViewController.m class, get a hold of the cell ( cellAtIndexPath: ) and then get a hold of that button with tag ( [cell.contentView viewWithTag:] ). 现在,在MyTableViewController.m类中,获得单元格( cellAtIndexPath: ,然后获得具有标签( [cell.contentView viewWithTag:] )的按钮的[cell.contentView viewWithTag:]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM