我有一个UITableViewController
里面有一个UITableView
和里面,在 UIView 下有一个UIView
和一个原型单元。
的内容UIView
是动态的,所以我想更改第一行动态的原点(y)。
当我更改UIView
框架和边界时
self.albumView.bounds=CGRectMake(0,0,self.albumView.frame.size.width, self.albumView.frame.size.height+100);
self.albumView.frame=CGRectMake(0,0,self.albumView.frame.size.width, self.albumView.frame.size.height+100);
UIView 重叠并隐藏行(我只能看到标题)
但是当我在它上面编写相同的代码
(void)viewWillAppear
时工作正常,但问题是我不知道高度,因为我还没有收到来自请求的数据。
我试过了
[self.view setNeedsDisplay];
[self.tableView setNeedsDisplay];
但似乎没有任何效果。我怎样才能解决这个问题?
我正在从我的 TableViewController 布局中添加快照
http://preview.otherlap.com/snap.png (我无法添加图片,因为我是新用户,所以有链接)
UIView 的高度根据 json 数据是动态的。我想要的只是更改表格第一行的原点(y)位置。
这里有一个示例代码
-(void)viewWillAppear:(BOOL)animated{
//self.albumView.bounds=CGRectMake(0,0,self.albumView.frame.size.width,self.albumView.frame.size.height+100);
//self.albumView.frame=CGRectMake(0,0,self.albumView.frame.size.width,self.albumView.frame.size.height+100);
}
- (void)viewDidLoad
{
[super viewDidLoad];
...load some data from server
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[jsonData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[jsonData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
self.albumView.bounds=CGRectMake(0,0,self.albumView.frame.size.width,self.albumView.frame.size.height+dynamicHeight); self.albumView.frame=CGRectMake(0,0,self.albumView.frame.size.width,self.albumView.frame.size.height+dynamicHeight);
}
如果我在 ViewWillAppear 上设置 UIView 高度,它会正确移动第一个单元格的原点。如果我在 connectionDidFinishLoad 上设置高度,它会与单元格重叠。
编辑:找到答案了,我自己找到了答案..
在 StoryBoard 上的 TableView 顶部添加 UiView 它会自动使其成为 tableHeaderView
所以解决方案是
CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = DynamicHeight;
self.tableView.tableHeaderView.frame = newFrame;
[self.tableView setTableHeaderView:self.tableView.tableHeaderView];