1
我想知道我怎么可以创建自定义UITableViewCell
与在UITableViewCell
这样三个部分:我如何创建一个自定义的UITableViewCell?
我想知道我怎么可以创建自定义UITableViewCell
与在UITableViewCell
这样三个部分:我如何创建一个自定义的UITableViewCell?
创建一个UITableViewCell空白XIB和设计细胞未落它的元素。在每个元素上设置任意标签(1,2,3 ...),以便稍后检索它们。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"xxx";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"NameOfTheBlankXIB" owner:self options:nil];
cell = [nibObjects objectAtIndex:0];
}
// get the elements inside the cell by tag and set a value on them
UILabel*label = (UILabel*)[cell viewWithTag: 1];
label.text = @"some text";
return cell;
}
另一种方法是去NIB和设置此视图控制器作为文件所有者和钩的小区向视图控制器的一个实例变量,像IBOutlet UITableViewCell *tableViewCell
。
现在将此与此实例一起加载,因为所有者自动将该单元挂钩到插座tableViewCell。
[[NSBundle mainBundle] loadNibNamed:@"NameOfTheBlankXIB" owner:self options:nil];
// at this point the cell is hooked to the ivar so you get a reference to it:
cell = self.tableViewCell;
但是,如何将三个单元分隔开 – GoldFire
创建一个包含线条和图标的PNG。拖放UIImageView并将其图像设置为该PNG。然后拖放UILabels用于其他任何事情。 – Jano