18
static NSString *cellIdentifier = @"cell";
if (tableView ==tableview1) 
{
    ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];        
    if (cell1 == nil) 
    {
        [[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self options:nil];
        cell1 = contactCustom;
    }
}

viewDidLoadメソッドを呼び出す前にメソッドにペン先名を登録するcellForRowAtIndex方法は?

4

10 に答える 10

35
-(void)viewDidLoad
{
   [super viewDidLoad];
   [self.tableView registerNib:[UINib nibWithNibName:@"cell" bundle:nil] 
   forCellReuseIdentifier:@"cell"];
}
于 2013-09-19T09:41:26.043 に答える
3

Apple は、IOS 5 以降の UITableView の register nib メソッドを提供しまし

元:

     In view did load you can register nib for UITableView like below
     [tableView registerNib:[UINib nibWithNibName:@"nibName" bundle:nil] forCellReuseIdentifier:@"identifienName"];

      In cellForRowAtIndexPath
      cell =  [tableView dequeueReusableCellWithIdentifier:@"identifienName"];
于 2013-03-12T12:16:47.710 に答える
0

セルを含む nib オブジェクトを、指​​定された識別子の下のテーブル ビューに登録します。

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier
Parameters

nib セルの作成に使用する nib ファイルを指定する nib オブジェクト。このパラメーターを nil にすることはできません。 identifier セルの再利用識別子。このパラメーターは nil であってはならず、空の文字列であってはなりません。

このドキュメントはあなたを大いに助けることができます

于 2013-03-12T12:34:29.740 に答える
0
static NSString *cellIdentifier = @"cell";
if (tableView ==tableview1) 
{
    ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];        
    if (cell1 == nil) 
    {
        cell1 = [tableview dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 

    }
}
于 2013-03-12T12:11:58.597 に答える
0
// First of all Declare an IBOutlet for your customCell in Your View Controller
IBOutlet ScoreCell *scoreCell;
// Synthesize it.
// Assign your view controller class to File Owner of your custom cell (Eg. File Owner of ScoreCell.xib)
// Then Assign Reference Outlet of ScoreCell.xib with Object 'scoreCell'
// Finally Create your custom Cell as follow :

ScoreCell *cell = (ScoreCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
    cell = [nib objectAtIndex:0];
}
于 2013-03-12T12:34:14.933 に答える
0

OBJECTIVE-Cの場合

//First TableView Declaration:
self.customTableView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];

//Then Nib Registration Registration:
[self.customTableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil]  forCellReuseIdentifier:@"customCellIdentifier"];

//Then Adding Tableview to self.view
[self.view addSubview: _customTableView];
于 2020-12-03T06:57:30.613 に答える
0

UINib *cellNib = [UINib nibWithNibName:@"Custom_cellTableViewCell" bundle:nil]; [self.tableView registerNib:cellNib forCellReuseIdentifier:@"Custom_cellTableViewCell"];

このコードは正常に動作しています

于 2018-03-24T08:06:49.923 に答える