开发者

Custom Cells in Table View in IPhone

开发者 https://www.devze.com 2023-03-21 00:25 出处:网络
Could anyone please help me by explaining how to use 2 custom cells in the same list view.. These two custom cells should appear in even and odd rows in the list. The odd 开发者_高级运维row cells shou

Could anyone please help me by explaining how to use 2 custom cells in the same list view.. These two custom cells should appear in even and odd rows in the list. The odd 开发者_高级运维row cells should have image at the left and labels in the right, while the even rows should have it other way..

Please help..


you could something like this on your UITableViewDataSource:

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

     if([indexPath row] % 2 == 0 ){
      //Create cell for even numbers
     }
     else{
      //Create cell for odd numbers
     }

}

Just a thought: I think you should create two distincts UITableViewCells, even if they have share some kind of logic between (switch an image and a label and you get the other). I say this, because the code becomes more clear for you and for a person that would see it in the future. The same is true for yourself: imagine that you need to change the cells with even values (had a more complicated logic, like 2 images, a button and a label (seems stupid but it could happen)) using 2 different UITableViewCells would really make your life easier.

One more thing to save you some time. If you dont know how to create custom UITableViewCells, you can use this tutorial:

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

0

精彩评论

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