Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create padding(spacing) between rows in tablview

This isn't a duplicate I read the other questions regarding this and none of them gave me what i needed , I'm creating a table view with custom cell and the style is grouped. I have 1 ImageView inside each row that is smaller then the whole row.How many cells I need to create is somthing i get from the db so I cant use static cells I need to have spacing between the rows,I cant figure out how to do this. I tried making the cell Bigger (320,143) and making it invisible which i managed to do but then when you press outside the image it still acting like i pressed the cell this is pretty much what i want to achieve

first pic

but this is what happens:

second pic

I need the cell to be the images size but to have spacing between diffrent rows. how can i do this?

like image 337
Eli Braginskiy Avatar asked Jul 05 '13 13:07

Eli Braginskiy


2 Answers

Many ways to do it, but I found this is the simplest and easiest way to do so.

Set UITableView style grouped. Then have two sections and each section has only one row. Replace your image in the row.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    //array is your db, here we just need how many they are
    return [array count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //place your image to cell
}
- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    //this is the space
    return 50;
}
like image 119
brianLikeApple Avatar answered Oct 04 '22 17:10

brianLikeApple


You can do it in just 3 lines.

First set gray color of your main view after that follow these lines.

cell.separatorInset = UIEdgeInsetsMake(20, 20, 20, 20);
cell.layer.borderWidth = 5;
cell.layer.borderColor = [UIColor whiteColor].CGColor;
like image 42
saurabh rathod Avatar answered Oct 04 '22 17:10

saurabh rathod