我有以下代码尝试添加附件视图,但我看不到任何内容
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
//add a button to set to accessory view
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"addsource.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeButton:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundColor:[UIColor clearColor]];
cell.accessoryView = button;
答案 0 :(得分:1)
您以编程方式创建了按钮,而不是在IB中(您将其放置在单元格视图上的某个位置),因此您还必须指定帧位置/大小。
例如,对于一次测试,尝试这样的事情:
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(200, 20, 20, 20);
[button addTarget:self action:@selector(changeButton:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundColor:[UIColor blackColor]];
cell.accessoryView = button;