在 UITableView 中使用 UITableViewCell [英] Using UITableViewCell in a UITableView

查看:20
本文介绍了在 UITableView 中使用 UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对某事有点困惑.我正在尝试创建一个自定义单元格,并且我想使用界面构建器的方式.

I'm a little confused with something. I'm trying to create a custom cell and I want to use the interface builder way.

我创建表格的正常方式是将表格设为:

The normal way I create a table is to have the table as:

.h

@interface AssessList : UIViewController {

    IBOutlet UITableView *tblAssessList;
}

@property(nonatomic, retain) UITableView *tblAssessList;

@end

.m

- (NSInteger)
numberOfSectionsInTableView:(UITableView *)tableView {
    return groupArray.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return totalArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }



    cell.textLabel.text = @"I am the text....";

        return cell;
}

现在我为单元格创建了一个新类,我想我知道如何将其放入.但是我可以将 .h 保留为

Now i've created a new class for the cell and I think I understand how to put that in. But can I leave the .h as

@interface AssessList : UIViewController

或者上面有完整表格的类/笔尖必须是一个 UITableViewController 吗?

or does the class/nib with the full table on it have to be a UITableViewController?

汤姆

推荐答案

上面有完整表的类/笔尖是否必须是一个UITableViewController?

does the class/nib with the full table on it have to be a UITableViewController?

没有.UITableViewController 只是一个便利的 UIViewController 子类,它有一个 UITableView 并且已经被设置为它的委托/数据源(它被声明为符合UITableViewDelegateUITableViewDatasource 协议),它还在 Xcode 为您生成的模板实现文件中为这些协议预先填充了方法实现.你也可以自己做这一切,我经常这样做.

No. A UITableViewController is just a convenience UIViewController subclass which has a UITableView and is already setup as its delegate/datasource (it is declared as conforming to the UITableViewDelegate and UITableViewDatasource protocols), it also has pre-filled method implementations for these protocols in the template implementation file which Xcode generates for you. You can just as well do all of this yourself, I often do.

然而,您应该为 UITableViewCell 创建一个 IBOutlet,以便您可以从 nib 文件中加载它(请参阅 从表视图编程指南中的 Nib 文件加载自定义表视图单元).

You should however make an IBOutlet for your UITableViewCell so that you can load it from the nib file (see the Loading Custom Table-View Cells From Nib Files in the Table View Programming Guide).

这篇关于在 UITableView 中使用 UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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