- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *TableSampleIdentifier = @"MyCell";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier];
if (cell == nil) {
cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableSampleIdentifier];
}
NSUInteger row = [indexPath row];
NSString *str;
if(row == 0){
str = @"0000";
}else
if(row == 1){
str = @"1111";
}else
if(row == 2){
str = @"2222";
}else
if(row == 3){
str = @"3333";
}
cell.username.text = str;
// cell.textLabel.text = str;//这个可以显示,但不是自定义
return cell;
}
------解决方案--------------------
if (cell == nil) {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = [array objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}
这样就OK