Это то, что я сделал.Опять же, некоторые приемы довольно неуклюжи, и я нуждаюсь в улучшении.
Сначала я создал новый подкласс UITableViewCell.Проблема в том, что я не могу проверить «включить» XIB.Как будто xib предназначен только для UIViewcontroller.Я полагаю, вы можете создать подкласс UIViewController с XIB, а затем создать другой подкласс UITableViewCell и переместить шаблон в ваш подкласс UIViewController.
Работает.
Затем я поместил эти функции:
@implementation BGCRBusinessForDisplay2
- (NSString *) reuseIdentifier {
return [[self class] reuseIdentifier];
};
+ (NSString *) reuseIdentifier {
return NSStringFromClass([self class]);
};
Для инициализации я делаю:
- (BGCRBusinessForDisplay2 *) initWithBiz: (Business *) biz
{
if (self.biz == nil) //First time set up
{
self = [super init]; //If use dequeueReusableCellWithIdentifier then I shouldn't change the address self points to right
NSString * className = NSStringFromClass([self class]);
PO (className);
[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil];
[self addSubview:self.view]; //What is this for? self.view is of type BGCRBusinessForDisplay2. That view should be self, not one of it's subview Things don't work without it though
}
if (biz==nil)
{
return self; //Useful if we only want to know the height of the cell
}
self.biz = biz;
self.Title.text = biz.Title; //Let's set this one thing first
self.Address.text=biz.ShortenedAddress;
[self addSubview:self.view];
довольно неловко.Это то, что другие говорят, что я должен делать, и без этого не получится.На самом деле я хочу, чтобы self.view было собой, а не subView of self.Но хей .... Не знаю, как это сделать иначе....
Затем я реализую это для cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//[FetchClass singleton].FetchController
if([BGMDCRFetchClass singleton].FetchController.fetchedObjects.count!=0){
BGCRBusinessForDisplay2 *cell = (BGCRBusinessForDisplay2*)[tableView dequeueReusableCellWithIdentifier:[BGCRBusinessForDisplay2 reuseIdentifier]];
if (cell == nil)
{
cell =[BGCRBusinessForDisplay2 alloc];
}
else{
while (false);
}
Business * theBiz=[[BGMDCRFetchClass singleton].FetchController objectAtIndexPath:indexPath];
cell = [cell initWithBiz:theBiz];
return cell;
//return theBiz.CustomCell;
}else{
UITableViewCell * tvc=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tvc"];
return tvc;
}
}
Обратите внимание, что я отделяю alloc от init.Это немного неловко.Вот почему в моем - (BGCRBusinessForDisplay2 *) initWithBiz: (Business *) biz
, если ячейка была инициализирована ранее, я просто не выполняю верхнюю часть инициализации.Я просто присваиваю значения Business * различным точкам в BGCRBusinessForDisplay2.
Я могу улучшить мои ответы, и они приветствуются.Пока это работает.