UIViewController内部的静态表视图[Xcode 5] [英] Static table view inside UIViewController [Xcode 5]

查看:81
本文介绍了UIViewController内部的静态表视图[Xcode 5]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到一个问题,即在一个UIViewController中,不能具有静态表视图内容

我没有收到警告/错误,但他也没有编译.是否有窍门?还是我必须使用旧的方法解决问题?

I'm aware of the problem that one is not able to have static table view content in a UIViewController in

I don't get a warning/error but he also doesn't compile. Is there a trick to it or do I have to use the old ways around it?

谢谢.

推荐答案

更新:使用最新更新(Xcode 5.1),似乎不再可能将静态单元格放入常规UIViewController中.我的答案仍然适用于UITableViewController.

是的,您可以在UIViewController中具有静态表视图内容.

Yes, you can have static table view content in UIViewController.

您需要做的只是:

-在界面构建器中创建表的静态单元格,然后按照自己的方式设计它们.

-Create the table's static cells in interface builder and design them the way you like.

-使UIViewController实现表视图的数据源并委托:

-Make the UIViewController implement table view's data source and delegate:

@interface MyViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>

-将表视图的委托和数据源连接到界面构建器中的视图控制器

-Connect the table view's delegate and dataSource to the view controller in interface builder

-实现-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section以返回您的单元格数. (例如return 10,是的,就这么简单)

-Implement -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section to return the number of your cells. (e.g. return 10, yes simple as that)

-在Interface Builder中将单元格作为IBOutlet连接到代码. 重要提示:请确保它们为strong,弱点将不起作用.例如@property (strong, nonatomic) IBOutlet UITableViewCell *myFirstCell;

-Connect your cells to your code as IBOutlets in Interface Builder. IMPORTANT: Make sure they are strong, weak won't work. e.g. @property (strong, nonatomic) IBOutlet UITableViewCell *myFirstCell;

-实施-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath以在索引路径处返回正确的单元格.例如:

-Implement -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath to return the correct cell at index path. e.g:

int num = indexPath.row;
UITableViewCell *cell;
switch (num) {
    case 0:
        cell = self.myFirstCell;
        break;
    case 1:
        cell = self.mySecondCell;
        break;
}
return cell;

如果应用所有这些步骤,则应该具有可工作的静态单元格,该单元格适用于单元格不多的表.非常适合您具有少量内容(可能不超过10-20个就足够了)的表.我几天前也遇到过同样的问题,并且确认它可以正常工作.有关我的答案的更多信息,请参见:最佳将Static-TableView-Cells添加到UIViewcontroller的方法?

If you apply all these steps, you should have working static cells that works for tables with not many cells. Perfect for tables that you have a few (probably no more than 10-20 would be enough) content. I've ran the same issue a few days ago and I confirm that it works. More info on my answer here: Best approach to add Static-TableView-Cells to a UIViewcontroller?

这篇关于UIViewController内部的静态表视图[Xcode 5]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆