【发布时间】:2014-09-05 01:03:56
【问题描述】:
这是我的第一个iOS 项目,所以我学到了很多东西,并且必须学习更多。
我了解到,为了在UITableViewCell 上容纳更多项目,我需要对其进行子类化然后使用它。我创建了TransactionCell,并在我的ViewController 中将其用作
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// make last cell visible: http://stackoverflow.com/questions/11928085/uitableview-not-visible-the-last-cell-when-scroll-down
tableView.contentInset = UIEdgeInsetsMake(0, 0, 120, 0);
[tableView registerNib:[UINib nibWithNibName:@"TransactionCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
TransactionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[TransactionCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
TransactionModel *transactionModel = self.transactionsModel.transactions[(NSUInteger) indexPath.row];
cell.dateAndMonth.text = transactionModel.date;
cell.name.text = transactionModel.name;
cell.amount.text = transactionModel.amount;
cell.categoryImage.image = [self getShortImage:[UIImage imageNamed:transactionModel.category]];
cell.transactionTypeImage.image = [self getShortImage:[UIImage imageNamed:@"Debit"]];
cell.imageView.contentMode = UIViewContentModeCenter;
return cell;
}
另外,我将单元格的高度设置为
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
我的xib 看起来像
但是,当我运行该项目时,我会看到以下内容
事情不合适!
问题
- 如何使标签完全显示在TransactionCell 上?
- 如何在不切断的情况下将所有元素放在一行中
我确定我需要学习其他东西,但不确定是什么
【问题讨论】:
-
在 Interface Builder 中更改标签的大小。
-
试过但没有解决
-
实现这个的方法太多了,auto layout auto resizing,一个很大的话题
-
我现在不在我的 Mac 上,但是如果您选择标签,然后单击带有自定义选项的选项卡,应该会有截断选项。像,截断尾巴,截断中间......等等。使用这些设置,直到它像你想要的那样运行。
标签: ios objective-c uitableview