UITableViewCell initWithStyle: UITableViewCellStyleSubtitle not working

I have a problem with displaying information in a cell, left and right. I know using initWithStyles UITableViewCellStyleSubtitle. I use this, but it does not work.

Here is a sample code:

- (UITableViewCell *)tableView:(UITableView *)ltableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Account Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)  {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cellidentifier];
    }

    Accounts *account = [self.fetchedResultsController objectAtIndexPath];
    cell.textLabel.text = account.name;

    cell.detailTextLabel.text = @"Price";

    return cell;
}

I can show cell.textLabel.text just fine, however I cannot get a simple "price" to be displayed. I tried various things like setting the font size cell.detailTextLabel.

I also tried UITableViewCellStyleValue1, as some suggested in older posts. Threw NSLog after setting to "Price", shows cell.detailTextLabel as null.

Not sure what I'm doing wrong.

Edit: I found this: cell.detailTextLabel.text NULL

if (cell == nil), ... , ?

+3
5

dequeue ( , ). , (cell == nil).

, , . , .

+17

, , , .

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
 {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
          cell = [[[UITableViewCell alloc]
             initWithStyle:UITableViewCellStyleSubtitle
             reuseIdentifier:CellIdentifier]
            autorelease];
 }


   cell.textLabel.text=[Array objectAtIndex:indexPath.row];
   cell.detailTextLabel.text=@"Price";


   return cell;
 }
+2

: UITableView ltableView, tableView. tableView.

+1

cell.detailTextLable.text cell.detailTextLabel.text. .

0

, , , . .

, viewDidLoad, cellForRowAtIndexPath:. reset , viewDidLoad __sCellRegistered = 0;

    static int _sCellRegistered = 0;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell *cell = nil;


if (__sCellRegistered == 0) {
    __sCellRegistered = 1;
    NSLog(@"register cell");

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"CellIdentifier"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CellIdentifier"];
};

if (!cell) {
    NSLog(@"dequeue");

    cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath];
}
0

All Articles