天天看點

使用自定義的tableViewCell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS

建立一個類ContactCell,繼承自UITableViewCell。建立一個xib檔案(ContactCell.xib),視圖為selfCell類。

使用自定義的tableViewCell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS

在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中使用自定義的cell。

static NSString *CellIdentifier = @"Cell";

    UINib *nib = [UINib nibWithNibName:@"ContactCell" bundle:nil];

   BOOL registered = NO;

   if(!registered){

    [tableView registerNib:nib forCellReuseIdentifier:@"Cell"];

    ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    registered = YES;

}

或者

    ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {

        cell = [[ContactCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    }