简体   繁体   中英

UITableViewCell Custom Cell set text

I want to set the text of a custom cell that inherits from UITableViewCell with my own method, here's my code:

- (void)updateCell {
    NSIndexPath* indexPath;

    indexPath= [NSIndexPath indexPathForRow:0 inSection:1];
    Somecell *cell = (Somecell *)[mytblview cellForRowAtIndexPath:indexPath];
    cell.b_freq.text = @"12332123";
    [mytblview reloadData];         
}

This code is not updating my UITableView as well. Are there any mistakes in my code or do you suggest using a different method?

You need to implement the UITableViewDataSource delegate method yourself rather than calling it and then modifying the cell that is returned:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    if (indexPath.section == 1 && indexPath.row == 0) {
       Somecell *cell = [[Somecell alloc] init];
       cell.b_freq.text = @"12332123";
       return cell;
    }
}

Implement the method and then return the cell that you want.

Check out the Apple documentation for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM