2
배경이 거의없는 테이블 뷰는 테이블 뷰를 String으로 채우는 fetchedResultsController로 채워집니다. 이제 각 tableview 셀의 각 String 옆에 단추를 추가하려고합니다. 지금까지 configureCell : atIndexPath 메서드에서 단추를 만든 다음 해당 단추를 하위 셀로 표 셀의 내용보기에 추가하려고했지만 어떤 이유로 단추가 표시되지 않습니다. 아래는 관련 코드입니다. 더 많은 코드를 게시하려면 원하는대로 물어보십시오. 어떤 도움이라도 대단히 감사합니다.iPhone 질문 : 어떻게하면 테이블 뷰 셀에 버튼을 추가 할 수 있습니까?
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
// get object that has the string that will be put in the table cell
Task *task = [fetchedResultsController objectAtIndexPath:indexPath];
//make button
UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setTitle:@"Check" forState:UIControlStateNormal];
[button setTitle:@"Checked" forState:UIControlStateHighlighted];
//set the table cell text equal to the object's property
cell.textLabel.text = [task taskName];
//addbutton as a subview
[cell.contentView addSubview:button];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
답변을 주셔서 감사합니다. [UIButton buttonWithType]을 으로 변경했습니다. CGRect buttonFrame = CGRectMake (0, 0, 40, 40); UIButton * button = [[UIButton alloc] initWithFrame : buttonFrame]; 아무 것도 나타나지 않습니다. 그것이 뭔가에 의해 가려진 것 같습니까? 편집 : 다른 문자열 텍스트에서 일부 텍스트를 볼 수 있습니다. 이제 나는 그것을 옮길 필요가있다. 당신이 도와 줘서 고마워. – Jake
'+ buttonWithType :'은'UIButtons'을위한 적절한 이니셜 라이저입니다. 다음과 같이하면됩니다 :'[button setFrame : CGRectMake (0,0,40,40)];' –