Github:https://github.com/nneeranjun/Maps.git
我有一个CoordinatesCustomCell(TableViewCell),它包含三个标签(我在CoordinatesCustomCell.h文件中链接了所有属性)。当我在TableViewController中使用重用标识符创建单元格并尝试更改标签文本时,在运行应用程序时它们似乎不会被更改。请使用上面的github链接查看我的代码。
DataTableViewController:
#import "DataTableViewController.h"
#import "CoordinatesCustomCell.h"
@import Firebase;
FIRDatabaseQuery*data;
@implementation DataTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CoordinatesCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CoordinatesCustomCell" forIndexPath:indexPath];
cell.latitude.text = @"Hello";
cell.longitude.text = @"Hello";
// Configure the cell...
return cell;
}
@end
CoordinatesCustomCell.h:
#import <UIKit/UIKit.h>
@interface CoordinatesCustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *index;
@property (weak, nonatomic) IBOutlet UILabel *latitude;
@property (weak, nonatomic) IBOutlet UILabel *longitude;
@end
答案 0 :(得分:1)
您需要在viewDidLoad
方法中为您的单元格调用第一个regiterNib或registerClass
[self.tableView registerClass:[CoordinatesCustomCell class] forCellReuseIdentifier:@"CoordinatesCustomCell"];
或
[self.tableView registerNib:[UINib nibWithNibName:@"CoordinatesCustomCell" bundle:nil] forCellReuseIdentifier:@"CoordinatesCustomCell"];
如果您使用.xib或storyboard作为原型单元格 别忘了设置
self.tableView.delegate = self;
self.tableView.datasource = self;