car*_*vil 4 iphone objective-c uitableview
我需要定义一个定制的UITableViewCell,其中UITableViewCellAccessoryCheckmark是的左侧UILabel.我应该将其定义为图像还是更智能的方式?
非常感谢,卡洛斯
这只是关于Apple文档的UIView .所以只需将其定义为UIView.
首先,您必须创建自己的UITableViewCell子类(在本例中,它称为MyCell).在此类中,在layoutSubviews方法中定义AccessoryView的框架.
- (void)layoutSubviews {
[super layoutSubviews];
self.accessoryView.frame = CGRectMake(0, 0, 20, 20);
}
Run Code Online (Sandbox Code Playgroud)
在视图控制器中,告诉表将此类用作单元格.另外,您必须将accessoryView设置为包含您图像的UIImageView.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"check.png"]] autorelease];
}
// Configure the cell.
return cell;
}
Run Code Online (Sandbox Code Playgroud)
当用户点击单元格时,您只需更改表格单元格的accessoryView图像即可.
| 归档时间: |
|
| 查看次数: |
3966 次 |
| 最近记录: |