高分IOS的TableView拖动到xib文件来创建

iOS 码拜 8年前 (2016-03-25) 1092次浏览
xcode中提供了直接拖动UITableView的方式来创建TableView,然后关联到.h文件中,这样好像省去了
初始化的麻烦。但是本人要怎么设置data和创建cell呢?
在线等
解决方案

10

ViewDidLoad方法里面可以设置data,然后实现UITableView的代理方法;
拖动只是帮你创建了UITableView而已,其它还的手动

10

[[NSBundle mainBundle] loadNibNamed:@”….Cell” owner:self options:nil].lastObject;

20

实现 UITableViewDelegate,UITableViewDataSource
@property (strong, nonatomic) IBOutlet UITableView *m_tableMedia;
设置数据源
m_tableMedia.delegate = self;
m_tableMedia.dataSource = self;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @”Cell”;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// 做你该做的事情
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明高分IOS的TableView拖动到xib文件来创建
喜欢 (0)
[1034331897@qq.com]
分享 (0)