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