Creating a UITableView Programmatically

后端 未结 9 2215
梦谈多话
梦谈多话 2021-01-31 14:26

I have an application in Xcode 4.6 which uses storyboards. I added a UITableView to a view controller class, which worked as expected. However, when I tried deleting the UITable

9条回答
  •  萌比男神i
    2021-01-31 15:08

    - (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
    {
        return 1;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)theTableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cellIdentifier = @"HistoryCell";
    
        UITableViewCell *cell = (UITableViewCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        cell.descriptionLabel.text = @"Testing";
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //Code for selection.
    }
    

    these are UITableView delegate methods.

提交回复
热议问题