UITableViewCell allocation issue - cell is not nil

前端 未结 1 1345
耶瑟儿~
耶瑟儿~ 2021-01-06 21:05
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @\"Cell2\";
    UILabe         


        
相关标签:
1条回答
  • 2021-01-06 21:12

    It sounds as if you are using iOS 5 (or later) and Storyboards.

    Under iOS 5 (or later), if you are using Storyboards and the TableView Controller, the dequeueReusableCellWithIdentifier: method is guaranteed to return a cell (provided that you have defined a cell with the given identifier in the Storyboard).

    If this is the case, the solution is to fully create the custom table cell in the Storyboard. Go to your Table View in your Storyboard, select Content:Dynamic Prototypes and make the Prototype Cells:1. Now layout your cell graphically to be exactly what you want. Now click on the cell and set Identifier:Cell2. You will now not need to create the label at runtime or check if it is nil. Full details including how to reference the labels you have setup are in the iOS 5 Release Notes (link below) or in many tutorials on the web.

    See the iOS 5 Release Notes section Configuring Table Views

    0 讨论(0)
提交回复
热议问题