Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
569 views
in Technique[技术] by (71.8m points)

ios - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...