2012-10-28 38 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

相关问题