맥은 참 나를 힘들게하는거 같다.
이번에 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;
}
이렇게 해제하자
'iPhone App' 카테고리의 다른 글
[iphone] Singletone Class만들기 (0) | 2011.07.14 |
---|---|
[iphone] UITableView에 Data를 넣어보자. (0) | 2011.07.13 |
[object-c] 컬렉션 사용하기 NSValue NSMutableArray 를 이용 (0) | 2011.06.23 |
[xcode] 아이폰에서 버튼 이벤트 발생시키기 (2) | 2011.06.17 |
google docs와 아이패드를 이용하여 Todo List 활용 (0) | 2011.01.07 |