开发者

How do I customize a UITableViewCell to display information differently (for dummies, drawing included)?

Alright, I might make this confusing, but hopefully not. So I have a UITableView that I want to section in 3: Details (A), Additional Details (B), and Assignment (C).

In the Details section, I want to just display information in the same way that the Contacts app does, but I don't know how to configure the UITableViewC开发者_StackOverflowell to display that way.

In the Additional Details section, I want to display a normal section, so I actually got that covered.

In the Assignment section, I want to have a combination where two cells are normal and will link to other controllers and one cell is just a plain button. Is there something special I need to do for the button cell?

Right now I have a mix of buttons, table cells, and labels, so it looks kinda bad, and thus I want to clean it up and make the interface consistent.

Here's a drawing of what I want to do:

How do I customize a UITableViewCell to display information differently (for dummies, drawing included)?

And on a side note, after I click on a cell and it slides to the next controller and then I go back, the cell is still selected. How can I get it to un-select itself after the action it's linked to is performed?

Thanks in advance for help!


All you need is a UITableView with Grouped style, then in tableView:cellForRowAtIndexPath: method you should check the section of the cell you are returning (ie. [indexPath section]) and return a cell based on that since all the cells within the same section should be of basically the same type and style. Not sure about the button, though really you should just have custom behavior for those cells in the tableView:didSelectRowAtIndexPath: method. Its all really about properly implementing the right delegates.


In cellForRowAtIndexPath should be something like this:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  ...
  ...
     if(indexPath.section == kAssignmentSection){

          if(indexPath.row == kAssignRow || indexPath.row == kTransferRow){

               cell.accesoryType = UITableViewCellAccessoryDisclosureIndicator;//Or Button
          }

     } 

}

Now in you should check for

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
   if(indexPath.section == kAssignmentSection){

      if(indexPath.row == kAssignRow){

          //Do your thing for AssingRow or any other index you know that needs to be processed
      }

   } 
}


I actually figured this out a couple of hours after I posted the question by digging into the documentation, and I ended up continuing work on my app and kind of disregarded this question. Anyway, it's actually quite easy to change how the cells look. It's all in the cell style.

The cell style determines how the cell looks; Default looks like B in my drawing, Value2 looks like A in my drawing.

And the arrow on right side is the accessory type, or in this case it's the DisclosureIndicator.

I guess this is a perfect example of read the documentation first before asking. So here's the docs I was reading:

  • UITableViewCell

  • UITableViewCellStyle

  • UITableViewCellAccessoryType

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜