這是我的第一個iOS
項目,所以我學到了很多東西,需要學習更多。iOS:如何在UITableViewCell中嵌入UILabel文本?
我瞭解到,爲了適應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中標籤的大小。 – 2014-09-05 01:07:14
嘗試過,但沒有解決它 – daydreamer 2014-09-05 01:10:13
有太多的方法來實現這一點,自動佈局自動調整大小,一個非常大的主題 – meim 2014-09-05 01:11:37