'ihpne'에 해당되는 글 1건

  1. 2011.07.13 [iphone] UITableView에 Data를 넣어보자.
iPhone App2011. 7. 13. 11:10

값을 넣는대는 프로퍼티를 이용해서 값을 return 해주는방법과

- (void)viewDidLoad

{

[super viewDidLoad];

if (data==nil) {

data = [[[NSMutableArray alloc] init ]retain];

[data addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"핫식스",[NSNumber numberWithInt:7000], nil] forKeys:KEYS]];

}

}


이렇게 view가 로드되고 넣어주는 방법이 있다.


내생각에는 후자가 메모리 관리상 나을것 같다.


그뒤에 row를 보여주는곳에는


- (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 = [NSString stringWithFormat:@"%@ (%d칼로리)",

[[data objectAtIndex:indexPath.row] objectForKey:@"name"],

   [[[data objectAtIndex:indexPath.row] objectForKey:@"price"] intValue]];

  


return cell;

}



이렇게 하자.


Posted by 동동(이재동)