Creating a UITableView Programmatically

后端 未结 9 2301
梦谈多话
梦谈多话 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:01

    #import "ViewController.h"
    
    @interface ViewController ()
    
    {
    
        NSMutableArray *name;
    
    }
    
    @end
    
    
    - (void)viewDidLoad 
    
    {
    
        [super viewDidLoad];
        name=[[NSMutableArray alloc]init];
        [name addObject:@"ronak"];
        [name addObject:@"vibha"];
        [name addObject:@"shivani"];
        [name addObject:@"nidhi"];
        [name addObject:@"firdosh"];
        [name addObject:@"himani"];
    
        _tableview_outlet.delegate = self;
        _tableview_outlet.dataSource = self;
    
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    
    {
    
    return [name count];
    
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    
    {
    
        static NSString *simpleTableIdentifier = @"cell";
    
        UITableViewCell *cell = [tableView       dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        }
    
        cell.textLabel.text = [name objectAtIndex:indexPath.row];
        return cell;
    }
    

提交回复
热议问题