2010-10-18 72 views

回答

1

YES,在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法使用此代码

UIImage *image = [UIImage imageNamed:@"yourImage.png"]; 

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height); 
button.frame = frame; 
[button setBackgroundImage:image forState:UIControlStateNormal]; 

button.backgroundColor = [UIColor clearColor]; 
cell.accessoryView = button; 
2

当然可以。只需更换整个accessoryView的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    // setup cell 
    UIImageView *aView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]] autorelease]; 
    cell.accessoryView = aView; 
    return cell; 
} 

编辑:如果你想使用你的配件像disclosureButton有必要多一点点。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath   
    // setup cell 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    button.frame = CGRectMake(0, 0, 44, 44); 
    [button setImage:[UIImage imageNamed:@"SettingsIcon.png"] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(accessoryButton:withEvent:) forControlEvents:UIControlEventTouchUpInside]; 
    cell.accessoryView = button; 
    return cell; 
} 

- (void)accessoryButton:(UIControl*)button withEvent:(UIEvent *)event { 
    UITableView *tv = (UITableView*)[[button superview] superview]; 
    UITableViewCell *cell = (UITableViewCell*)[button superview]; 
    NSIndexPath *ip = [tv indexPathForCell:cell]; 
    [tv.delegate tableView:tv accessoryButtonTappedForRowWithIndexPath:ip]; 
}