-1

Possible duplicate : enter link description here

I have 3 custom cell with Xib ( customCell1, customCell2, customCell3 ) and i need to set all of them only in one section ( i have don it before with 3 section without any problem ) .

customCell1 : is a static cell (an image)

customCell3 : is also a static cell (UITextView with a button)

customCell2 : must be dynamic (Its contain a MutableArray) which is may have different value in different situation...

My questions are : 1 : in consider to cell number two which have different rows how can i return : - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section my first Row must be (customCell1) and my last row must be (customCell3 ) in rows between must be (customCell2) ?

2 : in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath how can i separate this custom cells and call them in their own indexPath ?

Community
  • 1
  • 1
Sattar
  • 108
  • 4
  • 12

1 Answers1

0

If your first cell has to always be customCell1 and your last has to always be customCell3, which are both static and you only need 1 section, why not just using a tableView Header and Footer?

Example of checking IndexPath.row:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if(indexPath.row == 0){

        FirstCell *firstCell = (FirstCell *)[tableView dequeueReusableCellWithIdentifier:"TopCell"];

        //do your changes to the cell here

        return firstCell;

    }else if(indexPath.row == dataArray.count-1){

        LastCell *lastCell = (LastCell *)[tableView dequeueReusableCellWithIdentifier:"LastCell"];

        //do your changes to the cell here

        return lastCell;

    }

    NormalCell *normalCell = (NormalCell *)[tableView dequeueReusableCellWithIdentifier:"normalCell"];

    //do your changes to the cell here
    //For example
    cell.titleLabel.text = dataArray[indexPath.row].valueForKey("title"); 

    return normalCell;

}
Rob Contreras
  • 924
  • 6
  • 8
  • I know there are many ways to do it but my boss create this challenge , and he wants all of this tree be in one section without nay header and footer ... as i mentioned have done it before with 3sections. – Sattar Feb 27 '15 at 09:29
  • then you could check the indexPath.row i guess, if it's 0 then it's the first cell, if it's = dataArray.count-1 then its the last one, i'll update the answer to show you a code example – Rob Contreras Feb 27 '15 at 17:28