#iphone #objective-c #ipad
#iPhone #objective-c #iPad
Вопрос:
У меня есть следующий код, который пытается добавить вид аксессуара, но я ничего не вижу
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;
Ответ №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;