UITableview 기본 소스코드 - Objective-C

개발/iOS 2022. 1. 27. 09:08
반응형

헤더. 

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface ViewController2 : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
@property(nonatomic, strong) IBOutlet UILabel *oLabel1;
@property(nonatomic, strong) IBOutlet UITableView *oTableView;
@end

NS_ASSUME_NONNULL_END

 

소스

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }

    //cell.textLabel.text = [array objectAtIndex:indexPath.row];
    cell.textLabel.text = @"1";
    return cell;
}

 

 

반응형
admin