7

で困っていUITableViewCellます。

ストーリーボードにビュー コントローラーがあり、ビュー コントローラーに接続されていますMainViewControllerUITableViewCell3 つのラベルが含まれています。はUITableViewCellクラスに接続されていMTTableViewCellます。

// MTTableViewCell.h

#import <UIKit/UIKit.h>

@interface MTTableViewCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *mainLabel;
@property (strong, nonatomic) IBOutlet UILabel *statusLabel;

@end

// MTTableViewCell.m

#import "MTTableViewCell.h"

@implementation MTTableViewCell

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

// MainViewController.m

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;        
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    MTTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[MTTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }        

    NSString *namecell = @"namecell";
    NSString *statuscell = @"statuscell";           
    [cell.mainLabel setText:namecell];
    [cell.statusLabel setText:statuscell];        

    return cell;
}

問題は、実行時に何も表示されないことですMainViewController。私は何が欠けていますか?エラーは発生しません。空白のレコードが 1 つある空のテーブルビューだけです。

4

10 に答える 10

2

メインバンドルからセルをロードしていません:以下のコードを使用すると、これが機能します:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"FleetAccountCell";

FleetAccountCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[[NSBundle mainBundle] loadNibNamed:@"FleetAccountCell" owner:nil options:nil] objectAtIndex: 0];;
}
    return cell;
}
于 2015-08-06T07:50:38.553 に答える
2

インターフェイスビルダーを見てください-カスタムセルを「接続」していないはずです。ビューを実装したので、デリゲートを設定したくないので、「ファイル所有者」として設定する必要があります。たぶん、このヒントが役立ちますか?

于 2013-11-14T09:45:27.873 に答える
1

ここを見てみてください...あなたの問題に対する答えは      

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{

     CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath];

   // your content cell...


     return cell;
 }

ここでそれを読んでください PFQueryTableViewController はカスタムセルを表示しません

ご挨拶:)

于 2013-11-14T09:35:50.210 に答える
1

これは私のために働きます..

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"cellID";

FleetAccountCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[[NSBundle mainBundle] loadNibNamed:@"Your_nibName" owner:nil options:nil] objectAtIndex: 0];
}
[cell layoutIfNeeded];
return cell;
}
于 2016-08-03T02:48:59.183 に答える
0

セルを選択し、インスペクタータブで「インストール済み」にチェックマークを付けると機能します。

于 2016-08-16T11:41:35.107 に答える
0
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    TableViewCell *cell = (TableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil)
    {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
    }
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
于 2016-02-20T08:26:06.160 に答える
0

Rewrite you cellForRowAtIndexPath: method as below

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";

        MTTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CUSTOME_CELL_Nib_NAME" owner:nil options:nil] objectAtIndex: 0];;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }        

        NSString *namecell = @"namecell";
        NSString *statuscell = @"statuscell";           
        [cell.mainLabel setText:namecell];
        [cell.statusLabel setText:statuscell];        

        return cell;
    }
于 2013-11-14T09:49:25.883 に答える