我試圖創建和我的表視圖使用自定義的UITableView細胞,但它的作用時髦。當我運行應用程序的表看起來像這樣:自定義的UITableViewCell不正確顯示
這是正確的。然而,當我選擇一個單元格,視圖轉移到這一點:
據我所知,似乎選擇小區後,該小區視圖轉換到默認的UITableViewCell佈局與我的明星形象它背後......如果我繼續選擇每個小區我得到這個:
正如你所看到的,明星形象(我的自定義視圖)只顯示了(儘管扭曲),當我選擇單元格再次。
我已經通過Apple's tutorial試圖使自定義單元格,所以我知道我做的一切我應該,但沒有人在計算器上其他人也有類似的問題,當走了......
這裏我的項目的代碼。
的TableView控制器部首
//
// TableViewController.h
// CustomCell
//
// Created by Jordan Gardner on 1/29/14.
// Copyright (c) 2014 Jordan Gardner. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController
@end
的TableView控制器實現
//
// TableViewController.m
// CustomCell
//
// Created by Jordan Gardner on 1/29/14.
// Copyright (c) 2014 Jordan Gardner. All rights reserved.
//
#import "TableViewController.h"
#import "CustomCell.h"
@interface TableViewController()
@end
@implementation TableViewController
#pragma mark - Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
// Configure cell...
cell.textLabel.text = [NSString stringWithFormat:@"Item %@", [NSNumber numberWithInteger:indexPath.row]];
cell.imageView.image = [UIImage imageNamed:@"icon_folder.png"];
return cell;
}
@end
CustomCell部首
//
// CustomCell.h
// CustomCell
//
// Created by Jordan Gardner on 1/29/14.
// Copyright (c) 2014 Jordan Gardner. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIButton *favoriteButton;
@property (weak, nonatomic) IBOutlet UILabel *textLabel;
@end
CustomCell實施
//
// CustomCell.m
// CustomCell
//
// Created by Jordan Gardner on 1/29/14.
// Copyright (c) 2014 Jordan Gardner. All rights reserved.
//
#import "CustomCell.h"
@implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
那麼,有什麼建議,我怎麼能防止從意見行事如此扭曲,將不勝感激。提前致謝。
我建議你在自定義單元格中使用不同的名稱,而不是使用默認的'textLabel'和'imageView'。有時候,他們會發生衝突。 – n00bProgrammer
而錢去@ n00bProgrammer – ngoue
@ n00bProgrammer可能是對的,我首先將textLabel改爲別的。其次,你在使用自動佈局嗎?如果是這樣,請檢查您是否沒有模糊的佈局。 – ansible