Reputation: 28720
It seems a duplicate question to all of you but I have read all threads and I haven't found my answer yet so I decided to post a new question.
I am using default implementation of UITableViewCellStyleSubtitle
but the detailTextLabel
doesn't appear unless I create a new cell each time.
Here is the code
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[tblvUsersList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return (self.registeredUser && self.registeredUser.count > 0)?self.registeredUser.count:0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (self.registeredUser.count > indexPath.row) {
AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
if (self.currentViewType == ViewTypeUsers) {
UserModal* user = [self.registeredUser objectAtIndex:indexPath.row];
cell.textLabel.text = user.userName;
cell.detailTextLabel.text = user.email;
// NSLog(@"Detail Text is %@",cell.detailTextLabel.text);
//Console Prints Null here
}
return cell;
}
Upvotes: 0
Views: 128
Reputation: 4884
try to change the line
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
to
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Upvotes: 1