Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save keicoder/9202575 to your computer and use it in GitHub Desktop.
Save keicoder/9202575 to your computer and use it in GitHub Desktop.
oobjective-c : ios 7 basic tableview using storyboard with coredata from empty project
//ios 7 basic tableview using storyboard with coredata from empty project
//TWAppDelegate.h
//1. 스토리보드 사용하므로 기본 스텁코드 삭제
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
//스토리보드 사용하므로 기본 스텁코드 삭제
return YES;
}
//2. 스토리보드에서 테이블 뷰 컨트롤러 추가 및 embed in navigation controller
//3. 테이블 뷰 클래스(TWAlbumTableViewController) 생성 및 hook up with 스토리보드 테이블 뷰
//4. 테이블 뷰 클래스(TWAlbumTableViewController) 데이터 저장 프라퍼티(NSMutableArray *albums) 생성
//TWAlbumTableViewController.h
#import <UIKit/UIKit.h>
@interface TWAlbumTableViewController : UITableViewController
@property (strong, nonatomic) NSMutableArray *albums;
@end
//TWAlbumTableViewController.m
#import "TWAlbumTableViewController.h"
@implementation TWAlbumTableViewController
//albums getter 메소드
- (NSMutableArray *)albums
{
// if (!_albums) {
// _albums = [[NSMutableArray alloc] init];
// }
//위 코드와 동일함
if (!_albums) _albums = [[NSMutableArray alloc] init];
return _albums;
}
- (void)viewDidLoad
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
return [self.albums count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
@end
//5. 데이터 모델 (Album) 생성 - NSManagedObject Subclass
//Album.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Album : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSDate * date;
@end
//Album.m
#import "Album.h"
@implementation Album
@dynamic name;
@dynamic date;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment