2011-08-26 24 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