This is what I did. Again, some of the methods are rather inconvenient, and I need an improvement.
First, I created a new subclass of UITableViewCell. The problem is that I have no way to check the "enable" xib. It is as if xib was intended only for the UIViewcontroller. I suppose you can subclass the UIViewController with the XIB, and then merge another subclass of the UITableViewCell and move the template into your subclass of the UIViewController.
Works.
Then I put these functions:
@implementation BGCRBusinessForDisplay2 - (NSString *) reuseIdentifier { return [[self class] reuseIdentifier]; }; + (NSString *) reuseIdentifier { return NSStringFromClass([self class]); };
To initialize, I do:
- (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 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 set this one thing first self.Address.text=biz.ShortenedAddress;
[self addSubview:self.view]; embarrassing. This is what others say I have to do, and it wonโt work without him. In fact, I want self.view to be itself, not a subView of itself. But hei .... I do not know how to do it otherwise. ...
Then I implement this for 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; } }
Note that I am allocating alloc from init. This is awkward. This is why in my - (BGCRBusinessForDisplay2 *) initWithBiz: (Business *) biz , if the cell was initialized before, I just don't do the top of init. I simply assign Business * values โโto different outputs in BGCRBusinessForDisplay2.
I can improve my answers, they are welcome. While this is working.