我目前正在开发我的第一个iOS应用程序,并遇到了一个我似乎无法解决的问题.经过长时间的思考和奋斗,我决定在这里询问是否有人遇到过类似的问题,可以帮助我.
我有一个带有两个单元原型的UITableView.我可以毫无问题地渲染两种细胞类型,但是有一个小的捕获.一种细胞类型的高度为475px,而另一种仅为250px.渲染表视图时,表的每一行都具有相同的高度.我继续调试我的故事板,发现我的表视图的行高为475px.这对于较高的细胞来说很好,但对于较小的细胞,它会留下一个空白区域.
我希望能够根据渲染的单元格类型调整每行的高度.这可能吗?我正在考虑使用heightForRowAtIndexPath,但因为在执行时,单元格不存在,我无法检查某个索引处单元格的类.另外,在我的故事板中,我为两个单元格原型中的每一个指定了高度,但它没有在运行时反映出来.有谁知道如何解决这类问题?先谢谢你.
我试图从我的数据库中检索所有帖子,并按照DESC顺序列出它们的创建日期.到目前为止,我已经设法测试属于一个类别的所有帖子,但我想显示所有帖子,无论他们属于哪个类别.我知道我必须循环到每个类别,并从每个类别获取帖子,但我不知道如何.这是我的代码:
编辑:
def index
@institution = Institution.find(current_user.institution.id)
@categories = Category.all
@categories.each do |category|
@posts = Post.where("category_id = ? and institution_id = ?", category, @institution).order("created_at DESC")
end
authorize! :read, @post
respond_with(@posts)
end
Run Code Online (Sandbox Code Playgroud)
有人可以指点我正确的方向吗?
编辑2:我的观点(index.html.haml)
%h1 Listing posts
%table
%tr
%th Title
%th Description
%th User
%th Category
%th Type
%th Class
%th Institution
- @posts.each do |post|
%tr
%td= post.title
%td= post.description
%td= post.user_id
%td= post.category_id
%td= post.institution_id
Run Code Online (Sandbox Code Playgroud)