您的位置:首页 > 其它

因祸得福--学会了怎样创建并使用一个公用的模块类

2014-02-12 11:12 453 查看
通过前面的学习,知道怎样通过storyboard实现几个模块之间的导航。后来衍生到工作中,例如要实现一个这样的程序:

有一个多人的人员列表tableview,点击某个人员就会进入该人员的信息列表。

如果需要stroyboard实现,则需要创建很多的画板,画无数个segue,而且如果人员信息来自于数据库,则是动态的,所以需要一个公用的模块类来实现。

以上是背景,其实这是一种我原来一直想找的方法,也是受某专家的指点(他提到了这个方法,我不好意思再继续问详细的,想自己解决)

在网上找到这位http://www.cnblogs.com/minglz/p/仁兄的博客,里面第十四-十六章就解决了我的问题。

顺便说一下,后面准备好好看下他推荐的这本英文原版书《Beginning iOS 6 Development Exploring the iOS SDK》

实现方法就按他说的做,但是我自己将之升级为如此:

实现方法,就是在BIDFirstLevelController.m中重复再加一段

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"First Level";

NSMutableArray *array = [[NSMutableArray alloc] init];

// Disclosure Button

BIDDisclosureButtonController *disclosureButtonController1 = [[BIDDisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];

disclosureButtonController1.title = @"Disclosure Buttons 1";

disclosureButtonController1.rowImage = [UIImage imageNamed:@"disclosureButtonControllerIcon.png"];

[array addObject:disclosureButtonController1];

BIDDisclosureButtonController *disclosureButtonController2 = [[BIDDisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];

disclosureButtonController2.title = @"Disclosure Buttons 2";

disclosureButtonController2.rowImage = [UIImage imageNamed:@"disclosureButtonControllerIcon.png"];

[array addObject:disclosureButtonController2];

self.controllers = array;

}

通过上面的就将 BIDDisclosureButtonController对象添加到了controllers数组中,(如果是数据库中的成员,就循环添加),后面显示在tableview列表

中是通过在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}实现(该函数会通过得到的行数循环),这些方法都是继承于UITableViewController基类。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: