1. NXViewController.h에 다음을 입력하자


@interface NXViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, NSURLConnectionDataDelegate, NSURLConnectionDelegate>


@property (weak, nonatomic) IBOutlet UITableView table_view;

@property NSMutableData * json_data;

@property NSArray * json_array;


2. 윕에서 정보를 받아올 준비를 하자. NXViewController.m에 다음을 입력하자.

self.table_view.dataSource = self;

self.jason_data = [[NSMutableData alloc] init];


NSURL * url = [NSURL URLWithString:@"http://me2day.net/api/get_posts/codian.json"];

NSURLRequest * request = [NSURLRequest requestWithURL:url];

NSURLConnection * connection = [NSURLConnection connectionWithRequest:request delegate:self];


3. 정보를 받아오자.


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

[self.json_data appendData:data];

}


4. 정보를 다 받아온 후 정리하자.


-(void)connectionDidFinishLoading:(NSURLConnection *)connection

{

self.json_array = [NSJSONSerialization JSONObjectWithData:self.jsonData options:NSJSONReadingMutableContainers error:nil];


self.table_view.reloadData;

}


5. 테이블에 넣어주자.


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return self.json_array.count;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell = [tableView dequeueReusableCellWithIdentifier:@"tableCell"];

if (cell == nil)

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"tableCell"];


cell.textLabel.text = self.json_array[indexPath.row][@"body"];

cell.detailTextLabel.text = self.json_array[indexPath.row][@"author"][@"nickname"];


return cell;

}





첨부파일




Posted by 하남각목


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection(NSInteger)section

{

return self.shopping_list.count;

}


-(UITableViewCell)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell cell = [tableView dequeueReusableCellWithIdentifier:@"tableCell"];

if (cell == nil)

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"tableCell"];


cell.textLabel.text = self.shopping_list[indexPath.row][0];

cell.detailTextLabel.text = [NSString stringWithFormat:@"price = %4.0f, count= %d",

[self.shopping_list[indexPath.row][1] doubleValue],

[self.shopping_list[indexPath.row][2] IntegerValue]];


return cell;

}






참고자료




Posted by 하남각목
TAG DB, ios, tableView

0. Project의 타겟에 있는 Linked Frameworks and Libraries에 libsqlite3.dylib을 추가하자.

  또, 프로젝트 폴더에 .db 파일을 넣어주자.


1. NXViewController.h 파일에 다음을 추가하자.


#import <sqlite3.h>

@interface NXViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *table_view;

@property NSMutableArray * shopping_list;


2. db에 쿼리할 준비를 하자. NXViewController.m에 다음 코드를 추가하자.


NSString *dbFile = [[NSBundle mainBundle] pathForResource:@"shoppingList" ofType:".db"];


sqlite3 * db;

sqlite_open([dbFile cStringUsingEncoding:NSUTF8StringEncoding, &db);


sqlite_stmt * statement;

NSString * query = @"select * from shoppingTable";

sqlite_prepare(db, [query cStringUsingEncoding:NSUTF8StringEncoding], query.length, &statement, nil);


self.shopping_list = [[NSMutableArray alloc] init];


3. db에 쿼리를 날리고 배열에 정리하자.


while (sqlite3_step(statement) == SQLITE_ROW)

{

char * pItem = sqlite_column_text(statement, 0);

double aPrice = sqlite_column_double(statement, 1);

int aCount = sqlite_column_integer(statement, 2);


NSString * sItem = [NSString stringWithCString:pItem encoding:NSUTF8StringEncoding];

NSNumber * nPrice = [NSNumber numberWithDouble:aPrice];

NSNumber * nCount = [NSNumber numberWithInt:aCount];


NSArray * record = [NSArray arrayWithObjects:sItem, nPrice, nCount, nil];

[self.shopping_list addObject:record];

}


4. db에 쿼리가 끝났으면 db를 정리해주자.


sqlite3_finalize(statement);

sqlite3_close(db);


self.table_view.dataSource = self;




참고자료




Posted by 하남각목

controller 전환하기

iOS 2013.05.18 17:40


#import "NXViewController2.h"


NXViewController2 * new_controller = [[NXViewController2 alloc] initWithName:@"NXViewController2" bundle:[Bundle mainBundle]];


new_controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:new_controller animated:YES completion:^{}];




참고자료




Posted by 하남각목

Scroll View

iOS 2013.05.18 17:36


self.scroll_view.contentSize = CGSizeMake(320*4, 568);


UIImageView * image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"anna.jpg"]];

[image1 setFrame:CGRectMake(320*0, 0, 320, 568);


UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"anna2.jpg"]];

[image2 setFrame:CGRectMake(320*1, 0, 320, 568);


UIImageView * image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"anna3.jpg"]];

[image3 setFrame:CGRectMake(320*2, 0, 320, 568);


UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"anna2.jpg"]];

[image4 setFrame:CGRectMake(320*3, 0, 320, 568); 


[self.image_view addSubview:image1];

[self.image_view addSubview:image2];

[self.image_view addSubview:image3];

[self.image_view addSubview:image4];




참고자료




'iOS' 카테고리의 다른 글

<데이터베이스>db에 있는 데이터를 tableView로 보여주기  (0) 2013.05.18
controller 전환하기  (0) 2013.05.18
Scroll View  (0) 2013.05.18
View 변환하기.  (0) 2013.05.18
CGRect를 이용한 애니메이션  (0) 2013.05.18
image view에 새 이미지 설정하기.  (0) 2013.05.18
Posted by 하남각목

View 변환하기.

iOS 2013.05.18 17:29


1. 뷰 넣기.

[self.view insertSubview:self.dark_view atIndex:5];


2. 뷰 빼기.

[self.dark_view removeFromSuperview];




참고자료





'iOS' 카테고리의 다른 글

<데이터베이스>db에 있는 데이터를 tableView로 보여주기  (0) 2013.05.18
controller 전환하기  (0) 2013.05.18
Scroll View  (0) 2013.05.18
View 변환하기.  (0) 2013.05.18
CGRect를 이용한 애니메이션  (0) 2013.05.18
image view에 새 이미지 설정하기.  (0) 2013.05.18
Posted by 하남각목


CGRect frame = self.image_view.frame;

frame.origin.x -= 10;

frame.origin.y += 10;

frame.size.width += 10;

self.image_view.alpha = 1;


[UIView beginAnimations:@"" context:nil];

[UIView setAnimationDuration:1];


self.image_view.frame = frame;

self.image_view.alpha = 0;


[UIView commitAnimations];


  UIView animation 안에 있는 코드는 서서히 바뀐다.



참고자료



'iOS' 카테고리의 다른 글

<데이터베이스>db에 있는 데이터를 tableView로 보여주기  (0) 2013.05.18
controller 전환하기  (0) 2013.05.18
Scroll View  (0) 2013.05.18
View 변환하기.  (0) 2013.05.18
CGRect를 이용한 애니메이션  (0) 2013.05.18
image view에 새 이미지 설정하기.  (0) 2013.05.18
Posted by 하남각목


1.

NSString * image_file = [[NSBundle mainBundle] pathForResource:@"anna" ofType:".jpg"];

UIImage * image = [UIImage imageWithContentsOfFile:image_file];

self.image_view.image = image;


2.

UIImage *image;

image = [UIImage imageNamed:@"anna.jpg"];

self.image_view.image = image;



  2번은 디바이스의 해상도에 맞는 파일을 자동으로 잡아준다.



참고자료




'iOS' 카테고리의 다른 글

<데이터베이스>db에 있는 데이터를 tableView로 보여주기  (0) 2013.05.18
controller 전환하기  (0) 2013.05.18
Scroll View  (0) 2013.05.18
View 변환하기.  (0) 2013.05.18
CGRect를 이용한 애니메이션  (0) 2013.05.18
image view에 새 이미지 설정하기.  (0) 2013.05.18
Posted by 하남각목