2012-10-28 44 views
0

我在具有自定義UITableViewCell的表格視圖中創建了一個側面菜單。使用多個不同的自定義單元格創建複雜的UITableView

我創建了在下面使用可重複使用的電池:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
LeftMenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 

    NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"LeftMenuTableViewCell" owner:nil options:nil]; 

    for (UIView *view in views) { 
     if([view isKindOfClass:[UITableViewCell class]]) 
     { 
      cell = (LeftMenuTableViewCell*)view; 
      [cell.displayName setText:[NSString stringWithFormat:@"Cell 1"]; 

     } 
    } 
} 

return cell; 

}

我想知道如何創建其它細胞進行此表。該表格將像Facebook/Path側菜單一樣。例如 我的個人資料 設置 幫助 退出

每個將具有相同的設計,雖然不同的文字標籤和它旁邊的圖標。也可以在右側加載不同的視圖控制器。有人可以解釋這是如何完成的嗎?或者提供一個指向任何教程的鏈接,它解釋了使用多個不同單元格製作自定義表格視圖,我是否需要複製單元格.h,.m和NIB文件並分別創建每個自定義UITabelViewCell?

回答

0

使用相同的小區類,並把它作爲(由於沒有設計更改單元格,只有文字和圖像,改變),

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //some code 
    if() { //condition 1 
    cell.textLabel.text = @"My Profile"; 
    cell.imageView.image = [UIImage imageNamed:@"MyProfile.png"]; 
    } else if() { //condition 2 
    cell.textLabel.text = @"Settings"; 
    cell.imageView.image = [UIImage imageNamed:@"Settings.png"]; 
    } else if() { //condition 3 
    cell.textLabel.text = @"Logout"; 
    cell.imageView.image = [UIImage imageNamed:@"Logout.png"]; 
    } 
    //some code 
} 

didSelectRowAtIndexPath方法,

if() { //condition 1, say indexpath.row == 0 
    //go to firstviewcontroller 
} else if() { //condition 2, say indexpath.row == 1 
    //go to secondviewcontroller 
} else if() { //condition 3, say indexpath.row == 2 
    //go to thirdviewcontroller 
} 

這應該爲你工作嗎?

+0

是的:) - 字符數 – StuartM

相關問題