[英]UITableViewController not Displaying Custom Prototype Cells
我以前使用過UITableViewController,盡管其中大多數是與Nibs一起使用的,而不是與Storyboard一起使用的,我似乎無法獲得它來填充外觀或數據。
我的UITableViewController設置如下:
@implementation BFTBackThreadTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_dummyUsers = [[NSArray alloc] initWithObjects:@"@JonathanB",@"@NickyV",@"@Dman",@"C-LO-P", nil];
NSLog(@"%lu", (unsigned long)[_dummyUsers count]);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_dummyUsers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BFTThreadTableViewCell *cell = (BFTThreadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
// Configure the cell
cell.userLabel.text = [_dummyUsers objectAtIndex:[indexPath row]];
return cell;
}
我已經檢查了數組,所有4個對象都在其中,因此它們應該能夠填充行。
我的UITableViewCell class.h文件設置如下:
@interface BFTThreadTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *userLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeStamp;
@property (weak, nonatomic) IBOutlet UIButton *numberMessageThread;
@end
所有這些插座都連接到情節提要中的單元,並在使用助手編輯器時顯示連接。 cellIdentifier是正確的,請確保我復制並粘貼,而不是每次都嘗試正確鍵入。
故事板的設置如下:
盡管據我所知,我認為這應該可以工作,但仍然無法正常工作,但它仍在模擬器上運行,如下所示:
任何幫助將不勝感激。 先感謝您!
您必須在numberOfSectionsInTableView中返回一個非零數字:或只是完全刪除將默認為1部分的方法。
您在表格視圖中返回的節數為零,因此未顯示任何節。 用這個:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
我花了幾天的時間試圖找到解決方案。
我知道我遲到了游戲(這當然不是Keeasno的原型單元無法顯示的原因),但是如果上述答案對我的問題沒有幫助,那就是我使用了錯誤的“標識符”接口構建器中的“”字段。 確保在“接口”構建器中使用正確的“標識符”字段來提供可重復使用的標識符,請參見下文:
可訪問性標識符與原型單元無關,它與為需要可訪問性功能的用戶提供有用的信息(例如語音協助)有關,請參閱下面的鏈接以獲取更多信息:
按照我的邏輯,為了響應tableView:cellForRowAtIndexPath:如果dequeueReusableCellWithIdentifier返回nil值,我將自己創建一個實例。 代碼如下:
static NSString *cellIdentifier = @"CellIdentifier";
MaterialTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier: cellIdentifier];
if (cell == nil)
cell = [[MaterialTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:
cellIdentifier];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.