0

i'm using custom cell i learned in (This site). It's work in my old app but in this app i dont know why it's haven't work, when i run the above code he stuck with green error in line (NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];).

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CellIdentifier = @"CustomCell";
    PCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (PCustomCell *) currentObject;
                break;
            }
        }
    }
    P2Dict = [P2Rows objectAtIndex: indexPath.row];
    cell.Contracts.text = [P2Dict objectForKey:@"Contracts"];
    return cell;
}

http://ar2.co/SS2.png

Cezar
  • 55,636
  • 19
  • 86
  • 87

4 Answers4

1

custom cell xib .file take a tablecell.and in custom.m file implemented .and In view controller set the whole tableview through viewcontroller xib or programmatically .as ur choice .and set the delegate and datasourece methods.in datasource method written custom cell.code written below

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Custom";

CustomTableCell *cell = (CustomTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (!cell)
{
    UINib *nib = [UINib nibWithNibName:@"CustomTableCell" bundle:nil];
    NSArray *arr = [nib instantiateWithOwner:nil options:nil];
    cell = [arr objectAtIndex:0];
}

cell.textLabel.text =[arr objectAtIndex:indexPath.row];

}

Bajaj
  • 859
  • 7
  • 17
0

Did you have UITableviewCell(PCustomCell) at CustomCell.xib? You should show screenshot of the error here. It's will be helpful.

Seamus
  • 243
  • 1
  • 12
0

refer a following process. How to create a custom table cell is one kind of.

VocaTableCell is my case. make a your CustomTableCell.

enter image description here enter image description here


#import <UIKit/UIKit.h>

@interface VocaTableCell : UITableViewCell 
{
    UILabel *vocaLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *vocaLabel;

@end

#import "VocaTableCell.h"


@implementation VocaTableCell
@synthesize vocaLabel;

- (void)dealloc {
    [vocaLabel release];
    [super dealloc];
}
@end

Below code refer Befoe, Are you correctly make a customTableCell? below list check plz.

There are several ways to create about customTablecell.

My manner is very popular.

  1. CustomTabelCell of File's Owner should be a NSObject. (Very Important Default is Maybe UITableCell. You Must be a change File's Owner NSObject(NSObject mean is id type!))

  2. CustomTableCell link a Object Class a your CustomTableCell Class.

  3. Referencing Outlets link Not File's Owner, must be Your Directly link a CustomTableCell.


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Custom";

    CustomTableCell *cell = (CustomTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell)
    {
        UINib *nib = [UINib nibWithNibName:@"CustomTableCell" bundle:nil];
        NSArray *arr = [nib instantiateWithOwner:nil options:nil];
        cell = [arr objectAtIndex:0];
    }

    cell.textLabel.text =[arr objectAtIndex:indexPath.row];
}
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
0

Your error states: "Could not load NIB in bundle named "CustomCell"". So there lies your problem.... what is your xib named?

Mario
  • 4,530
  • 1
  • 21
  • 32