【问题标题】:Tableview Custom cell mutliple values on one labelTableview自定义单元格在一个标签上的多个值
【发布时间】:2015-02-17 06:45:06
【问题描述】:

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

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

- (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;
}

【问题讨论】:

  • 这里提供链接,我会上传...
  • 那么问题出在哪里?看不到您上传的图片。
  • cell.textLabel.numberoflines = 0;
  • @FahimParkar 现在不需要上传,我自己解决了。 :)

标签: objective-c uitableview ios7 custom-cell


【解决方案1】:

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

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

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

caption.text = ...

你也可以用同样的方式使用 UIimage。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2019-05-13
    • 2016-04-05
    • 1970-01-01
    相关资源
    最近更新 更多