Created
December 18, 2015 06:39
-
-
Save tlkahn/e301c33686f995940d32 to your computer and use it in GitHub Desktop.
ios tableview basic boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> | |
@property (weak, nonatomic) IBOutlet UITableView *tableView; | |
@property (strong, nonatomic) NSMutableArray *data; | |
@end | |
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
NSMutableArray *ns = [NSMutableArray arrayWithObjects:@"1",@"2",nil]; | |
self.data = ns; | |
self.tableView.delegate = self; | |
[self.tableView reloadData]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSLog(@"You have selected # %ld", (long) indexPath.row); | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return self.data.count; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STTwitterTVCellIdentifier"]; | |
if(cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"STTwitterTVCellIdentifier"]; | |
} | |
cell.text = self.data[indexPath.row]; | |
return cell; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment