예를 들어, 다른 메뉴로 연결되는 설정 메뉴가 있고 모두 동일한 스타일을 가지고 있습니다.다양한 테이블 뷰에서 동일한 UITableView 스타일을 원한다. 어떻게 할 수 있습니까?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[self dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
}
BOOL isFirstRowInSection = NO;
if (indexPath.row == 0) isFirstRowInSection = YES;
BOOL isLastRowInSection = NO;
int numberOfRowsInSection = [tableView.dataSource tableView:self numberOfRowsInSection:indexPath.section];
if (indexPath.section == 0 && indexPath.row == numberOfRowsInSection - 1) {
isLastRowInSection = YES;
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:cell.bounds];
imageView.image = cellBackgroundImage(cell.bounds.size, isFirstRowInSection, isLastRowInSection);
cell.backgroundView = imageView;
//cell.textLabel.text = @"This is a cell";
return cell;
}
내가이 클래스는 기본 설정 메뉴와 모든 하위 메뉴를 사용할 수 싶지만, 나는 그들이 무엇을 각 셀의 텍스트처럼 자신의 데이터를 제공 할 때 : 테이블 뷰 셀 cusomisation는 다음과 같이 이루어집니다 여기에서 셀 스타일링 방법을 택하고 싶습니다.
어떻게하면됩니까? 현재의 생각은 데이터 소스 프로토콜의 일부를 응답 할 수있는 자신의 대리자로 복제하는 것입니다.
감사합니다. 코드 복사 및 붙여 넣기는 결코 좋은 생각이 아닙니다. 한 곳에서 그것을 바꾸라고 말하면 다른 곳으로 복사하여 붙여 넣기를하지 않는 한 손에 엉망이됩니다. – Andrew
완전히 사실입니다. 첫 번째 해결 방법이 효과가 있는지 알려주세요. 또한 이러한 셀을 자주 사용할 계획이라면'[UITableViewCell formattedCell]'과 같은 것을 호출 할 때 미리 포맷 된 셀을 뱉어내는 UITableViewCell에 카테고리를 구현할 수 있습니다. – ravron