Tableview在一个标签上自定义单元格多个值

时间:2015-02-17 06:45:06

标签: objective-c uitableview ios7 custom-cell

我的问题是我想只使用一个原型单元格在标签值中显示数组元素,但我得到的是这个

这是我的代码。有人可以帮我吗? 对不起,我的英语不好。 :)

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imgProfilePic.layer.cornerRadius = self.imgProfilePic.bounds.size.width/2;
    self.imgProfilePic.layer.masksToBounds = YES;

    self.lblBadge.layer.cornerRadius = self.lblBadge.bounds.size.width/2;
    self.lblBadge.layer.masksToBounds = YES;

    self.userData = [NSMutableArray arrayWithObjects:@"Projects",@"Tags",@"Saved Searches",@"Filters",@"Groups",@"Users",@"Settings",@"Abouts Us", nil];

}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [self.userData count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

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

    NSString *identifier = @"myCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.textLabel.text = [self.userData objectAtIndex:indexPath.row];
    return cell;
}

1 个答案:

答案 0 :(得分:1)

如果您使用故事板并且您知道元素的数量,您可以将标签放入单元格并全部使用它们。但是你必须设置标签标签:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

UILabel * caption =(UILabel*)[cell viewWithTag:(1)];

caption.text = ...

您也可以使用相同的方式使用UIimage。

相关问题