2012-02-07 165 views
0

我想在我的IOS应用程序在xcode中实现这种事情。IOS添加自定义属性到uitableviewcell

HTML: <div data-foo="foobar"></div>

基本上,我有一个UITableViewCell,我想添加自定义属性,我可以获取和设置。

我知道我可以使用detailTextLabel.text,使文字透明的,但我真正需要的是,我可以设置和获取,就像在HTML中data-foo幕后的东西,但有uiTableViewCell在Xcode中/ IOS。

我该如何做到这一点?

+0

你为什么认为你需要这个?将data-foo存储在dataSource中。解释你真的**想要做什么。你想在你的单元格中引用像UITextViews或UIButtons这样的UIControls吗?你不需要data-foo。在我看来,一切都可能与indexPath – 2012-02-07 20:16:16

+0

@MatthiasBauch我需要这个存储数据,我可以用来从表和数据源删除输入。 – 2012-02-07 20:23:49

回答

1

也许你可以创建一个名为MyTableCell的类,并在那里创建一些对象。在故事板中,将TableViewCell设置为MyTableViewCell。然后当你创建一个TableViewCell

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

MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:@"MyTableCell"]; 

//configure cell 
//make any changes to the TableViewCell class with cell.myObject  

return cell; 
}