iPhone App2011. 7. 12. 18:07

맥은 참 나를 힘들게하는거 같다.

이번에 xcode 4를 깔았는데 이게 더 나은거 같다. 이건 중요하지 않고

일단 xib 에서 tableView를 하나 만들고.. 기존에 View가 있으면 지우고 만든다.

그다음에 오른쪽 버튼으로 연결후

헤더에서

#import <UIKit/UIKit.h>


@interface CalrorieCalViewController : UITableViewController {

NSMutableArray *data;

}


@property (nonatomic, retain) NSMutableArray* data;

@end


이런식으로 바꾼다.


그뒤에


-(NSMutableArray*) data {

if (data==nil) {

data = [[NSMutableArray alloc] init];

[data addObject:[NSMutableDictionary dictionaryWithObject:@"핫식스" forKey:@"name"]];

[data addObject:[NSMutableDictionary dictionaryWithObject:@"NF소나타" forKey:@"name"]];

  

}

return data;

}


이렇게 data를 만들고


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


return [self.data count];

}


이렇게 몇개 보일지 카운터를 알려주고


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

  

static NSString *CellIdentifier = @"Cell";

  

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}

  

cell.textLabel.text = [[self.data objectAtIndex:indexPath.row] objectForKey:@"name"];

return cell;

}


이렇게 row를 돌면서 데이터를 뿌려준다.
마지막으로

- (void)viewDidUnload

{

[super viewDidUnload];

self.data = nil;

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}


이렇게 해제하자


Posted by 동동(이재동)