Creating a UITableView Programmatically

后端 未结 9 2223
梦谈多话
梦谈多话 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条回答
  •  我在风中等你
    2021-01-31 15:19

    - (void)viewDidLoad {
         [super viewDidLoad];
         arr=[[NSArray alloc]initWithObjects:@"ABC",@"XYZ", nil];
         tableview = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];   
         tableview.delegate = self;
         tableview.dataSource = self;
         [self.view addSubview:tableview];
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return arr.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
    
        if(cell == nil)
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
        }
    
        cell.textLabel.text=[arr objectAtIndex:indexPath.row];
    
        return cell;
    }
    

提交回复
热议问题