82846

Two different UITableViewCell in UITableView

Question:

I want to create one TableView that has 2 section rows. this table has 2 section (first section has 1 cell and second section has 3 cell)

notice:cell of first section different with cells of second section.

this is my code but don't working!!!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSArray *name = [_names objectForKey:key]; static NSString *CellIdentifier2 = @"CustomerCell"; if (indexPath.section == 0) { static NSString *CellIdentifier = @"myCell"; FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... cell.nameLable.text = [NSString stringWithFormat:@"blue"]; cell.numberLable.text = [NSString stringWithFormat:@"1212432543"]; cell.profileImage.image = [UIImage imageNamed: @"profile.png"]; return cell; //this part not working !!! XD } else if (indexPath.section >= 1) { CustomerCell *cell = (CustomerCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier2]; if (cell == nil) { NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil]; for (id currentObject in topLevelObject) { if ([currentObject isKindOfClass:[CustomerCell class]]) { cell = (CustomerCell *)currentObject; break; } } } // Configure the cell... cell.titleLable.text = [name objectAtIndex:indexPath.row]; return cell; } return nil; }

<strong>customerCell</strong> & <strong>FirstCell</strong> are tow UITableViewCell for custom cells. when I to do run this code only section one not working and don't show cell but another section is working please guide me and tell me where is it my mistake.

Answer1:

Try this:

FirstCell *cell = (FirstCell *)[tableView dequeueReusableCellWithIdentifier:strEvalIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; }

Answer2:

Try using the same code as in the second cell.

if (indexPath.section == 0) { FirstCell *cell = (FirstCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier2]; if (cell == nil) { NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:nil options:nil]; for (id currentObject in topLevelObject) { if ([currentObject isKindOfClass:[FirstCell class]]) { cell = (FirstCell *)currentObject; break; } } // Configure the cell... cell.nameLable.text = [NSString stringWithFormat:@"blue"]; cell.numberLable.text = [NSString stringWithFormat:@"1212432543"]; cell.profileImage.image = [UIImage imageNamed: @"profile.png"]; return cell; }

Recommend

  • View tableview cell text on table view cell button
  • jqgrid : setCell method > how to set class of the fourth parameter?
  • Why UITableViewCell needs to be registered?
  • About dequeueReusableCellWithIdentifier:
  • iOS Container View in UITableViewCell
  • cellForItemAt is not calling in collectionView
  • Stop MKMapView from reloading
  • Ensure a valid date inside the cell in Excel
  • Highlight words inside the string
  • UITableView and UILabel repeating
  • Cells become empty after scrolling. (Xcode)
  • Changing app.servlet.version does not affect web.xml
  • How remove node from the document method using xslt
  • Parsing an NSXMLElement in Cocoa
  • Sending message to Clojure application from terminal
  • Accessing posted json with ring format-params middleware
  • Prediction using a natural spline fit
  • How to avoid stalled DB connections with TomEE's JDBC connection pool?
  • Jena Sparql Error java.lang.Integer
  • UITableView cell: selectedBackgroundView without showing backgroundView
  • Fuseki 1.0.1 SPARQL Update returns 404
  • Populating a UITableView in Firebase a Set Number of Cells at a time
  • how to convert a unix timestamp into nsdate in iphone [duplicate]
  • Error: Wrapper cannot find servlet class VendorRegistration or a class it depends on
  • Merging values from DB using Liquibase and Spring
  • reset the XMPP connection if the page gets refreshed
  • Flex: DataGrid column formatting of numbers
  • VHDL - iSIM output uninitialised, doesn't change states
  • How to require a namespace programmatically
  • Is there a better method than to reuse a complicated table in DocBook?
  • Why won't my UITableViewCell deselect and update its text?
  • Sending Content-Type application/x-www-form-urlencoded WSO2 ESB
  • CERN ROOT exporting data to plain text
  • Trouble saving JSON data for use by multiple UIViews [duplicate]
  • Jetty 9 HashLoginService
  • Cancel a live stream “fast motion” catch-up in Flash
  • Why value captured by reference in lambda is broken? [duplicate]
  • Why joiner is not used after Sequence generator or Update statergy
  • Recursive/Hierarchical Query Using Postgres
  • UserPrincipal.Current returns apppool on IIS