質問

When I create new xib in ios (New File -> User interface -> Empty ) can i use that nib as my uitableviewcell in my table ?

I create all uitableview in code (i don't use stroyboard for it ), but I want customize my cell nice.

Thanks for your help

役に立ちましたか?

解決

Yes, you can, and you will also want at least a corresponding header file to place the IBOutlet properties in so that your table view data source can populate the objects (labels, images…).

Then in your table view controller (viewDidLoad) you register the nib something like:

UINib *myNib = [UINib nibWithNibName:@"MyNibName" bundle:nil];
[tv registerNib:myNib forCellReuseIdentifier:kCellIdentifier];

Making sure you define the kCellIdentifier:

#define kCellIdentifier @"CellIdentifier"

Then in cellForRowAtIndexPath:

static NSString *CellIdentifier = kCellIdentifier;

MyCell *myCell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

[myCell setMyLabel:@"ABCD"];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top