2011-08-26 19 views
0

我看到一些应用程序有<东西>在表格视图单元格中。 如果我按左括号或右括号,它们之间的东西(文本或图形)会改变。 它用于设置菜单。 我该如何做到这一点?有没有任何代码?如何在桌面视图中制作左右托架?

回答

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

UIImageView *imgView; 
UIImageView *imgView1; 
UILabel  *lblName; 
if(cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero    reuseIdentifier:CellIdentifier] autorelease]; 

    imgView = [[UIImageView alloc] initWithFrame:(5,0,20,62)]; 
    [imgView setImage:[UIImage imageNamed:@"leftimg.png"]]; 
    imgView.tag = 55; 
    [cell.contentView addSubview:imgView]; 
    [imgView release]; 

    lblName = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 100, 25)]; 
    lblName.tag = 77; 
    [cell.contentView addSubview:lblName]; 
    [lblName release]; 

    imgView1 = [[UIImageView alloc] initWithFrame:(200,0,20,62)]; 
    [imgView1 setImage:[UIImage imageNamed:@"rightimg.png"]]; 
    imgView1.tag = 66; 
    [cell.contentView addSubview:imgView1]; 
    [imgView1 release]; 
} 
else  
{ 
    imgView = (id)[cell.contentView viewWithTag:55]; 
    imgView1 = (id)[cell.contentView viewWithTag:66]; 
    lblName = (id)[cell.contentView viewWithTag:77]; 

} 
lblName.text = @"your text"; 

return cell; 

}

+0

我几乎明白了。括号前为括号内的文本,括号内为文本或grahic。我仍然不知道如何将它放在括号内。我是初学者。它看起来像这样:text jaycons

+0

按照我的代码放置imageview,在图像之间放置UILabel并将其写入。 – PJR

+0

我已经编辑了我的答案。使用它它会为你工作。并根据你的需要改变位置... – PJR

1

您需要通过继承UITableViewCell并将两个按钮添加到单元格视图来创建自定义tableview单元格。

+0

谢谢。有没有任何代码? – jaycons

+0

这取决于你的确切视图。网络和SO上有很多例子, http://stackoverflow.com/search?q=custom+UITableViewCell – mjisrawi