0

enter image description hereHere, I have a TableView with one section. However, I have 2 cells. I want numberofRowsInSection to return 2 different values for different rows of the same section. But, I can't access the row in numberofRowsInSection function. Can someone please tell me how to attain this?

enter image description here

Isha Balla
  • 733
  • 2
  • 9
  • 25
  • refer this answer http://stackoverflow.com/questions/30476340/table-view-issues-in-swift-ios/30476653#30476653 – Rizwan Shaikh Jan 27 '16 at 10:17
  • The solution written there is for multiple section. I am searching an answer for single section – Isha Balla Jan 27 '16 at 10:21
  • can you show me an image of your storyboard and/or code so I can understand this better – Unis Barakat Jan 27 '16 at 10:23
  • just did. please check. Uploaded two images – Isha Balla Jan 27 '16 at 10:27
  • Please always post actual code as text, not as screenshots only. Thanks. Picture of code is not searchable, not indexable and not testable. – Eric Aya Jan 27 '16 at 10:41
  • I think you are confused a bit. numberOfRowsInSection should return the number of CELLS aka rows in the section, I cannot see what do you mean by returning different number of rows for each row? Please elaborate. – ysholqamy Jan 27 '16 at 10:46

1 Answers1

0

numberOfRowsInSections should return the count of cells in that section, if you want to display two different type of cell (ex. CellType1 and CellType2), you should do logic inside

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
       if(indexPath.row == 0){ return CellType1; }
       if (indexPath.row == 1) { return CellType2; }
    }
}

you can't return multiple values from that method, apple has not written that method to return multiple values

alessioarsuffi
  • 561
  • 5
  • 16