2015-06-12 202 views
2

我正在尝试ti实现表格视图单元格与自定义在那种情况下,我需要在特定单元格中根本没有动态高度。 显示是否可以为uictableview单元定义动态高度,如果是,我该如何执行此操作?UITableView自定义单元格

谢谢。

+1

后实现此委托的方法是什么ü尝试第一 –

+1

尝试,当你问到有一些代码。这将有助于他人确定你的确切要求 –

回答

3

为UITableView的

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(indexPath.row == rownumber) { 
     return 150.0; // Custome size as per requirement 
    } 

    return 50.0;/// some default size 
} 



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 5; 

} 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(indexPath.row == 3) { 
     return 150.0; 
    } 

    return 50.0; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // We are looking for cells with the Cell identifier 
    // We should reuse unused cells if there are any 
    if(indexpath.row==0 || indexpath.row==1 || indexpath.row==3){ 
     static NSString *cellIdentifier = @"Cell1"; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    // If there is no cell to reuse, create a new one 
    if(cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 
    } 
    else if(indexpath.row==2){ 
    static NSString *cellIdentifier = @"Cell2"; 
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    // If there is no cell to reuse, create a new one 
    if(cell == nil) 
    { 
     cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 



    return cell; 
} 
+0

谢谢yagnesh的帮助.. –

+0

让我知道如果这是工作或否? –

相关问题