나는 큰 얼간이 목장 아이폰 OS 가이드를 읽고 있어요 내가 여기에이 코드 조각에 대한 질문이 있습니다정확히 어떻게합니까 NSIndexPath 행 속성 작업
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[p description]];
return cell;
}
BNRItemStore 그냥 데이터 저장소 개체 및 I입니다 초기화 메소드에서 5 개의 BNRItem 객체를 이미 추가했습니다. 그러면 해당 문자열 설명이 UI에 인쇄됩니다. 단지 BNRItemStore의 항목을 검색하고 변수에 할당합니다 :
BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
내가이 줄을 이해하는 방법은 objectAtIndex가 있다는 것입니다 : 내 혼란은 특히 여기이 선에 관한 것입니다. 내가 가진 질문은 다음과 같습니다.
objectAtIndex는 어떻게 [indexPath row] 인수를 사용하여 다섯 개의 모든 개체를 * p 변수로 반환 할 수 있습니까? indexPath 객체가 단일 섹션과 단일 행을 보유한다는 인상하에있었습니다. 따라서 row 속성은 단일 행 인덱스를 반환합니다. 여기서는 배열이 루프되고 5 개의 내용이 변수에 반환 된 다음 UI에 인쇄되는 것처럼 보입니다. 아니면 그게 무슨 일이 아닌가? 실제로 여기서 행 속성은 무엇입니까?
애플 문서가 그런 식으로 설명하기를 바란다면, 이러한 데이터 소스 방법이 많아서 무엇이 뒤에서 일어나고 있는지 정확히 알 수 없기 때문입니다. –
@MikaSchiller -이 설명서는 도움이 될 수 있습니다. http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/AboutTableViewsiPhone/AboutTableViewsiPhone.html –
빠른 질문 : 아직 5 개의 항목이 있습니다. (jQuery과 *)있는 tableView numberOfRowsInSection : (NSInteger) 섹션 { - (NSInteger)있는 tableView : 데이터 저장소와 나는 절 0 2 개 항목 그래서 일단 내가 이런 짓을 했을까 섹션 1에서 3 개 항목을 넣을 \t 경우 (제 == 0) { \t \t \t 창 2} \t 경우 (제 == 1) {\t \t return 3 \t } –