当前位置: 代码迷 >> Iphone >> 自定义UiTableView不能显示,该如何解决
  详细解决方案

自定义UiTableView不能显示,该如何解决

热度:75   发布时间:2016-04-25 05:49:18.0
自定义UiTableView不能显示
- (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