Contenu connexe Similaire à 아이폰강의(6) pdf (20) 아이폰강의(6) pdf1. Chapter 8
Custom TableView Cell
Bit Academy
2. •
• NIB .
• NIB Top Level .
• .
3. • ,
, .
•
.
• UITableViewCell
.
5. NIB
• File->New IOS User Interface View
Next PhotoTableCell
• PhotoTableCell.xib
• PhotoTableCell.xib IB View TableViewCell
TableViewCell UIImageView, UILabel
.
• UIImageView Mode Aspect To Fit
.
6. • IB
• IB IBOutlet property
• viewWithTag:
• Tag 0 .
7. • tableView: cellForRowAtIndexPath:
, PhotoTableCell.nib tag
• nib (
)
• [NSBundle mainBundle]
8. NSBundle Class
• NSBundle
.
• mainBundle :
NSBundle . + (NSBundle *)mainBundle
• - (NSArray *)loadNibNamed:(NSString *)name owner:
(id)owner options:(NSDictionary *)options
name category NSBundle
nib The name of the nib file, which need not include
the .nib extension.
owner :nib File's Owner object.
options : A dictionary containing the options to use when
opening the nib file. For a list of available keys for this dictionary, see
“Nib File Loading Options. Nib Toplevel
( root View 0
.)
9. tableView: cellForRowAtIndexpath:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self appDelegate].photoArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PhotoTableCell" owner:self
options:nil];
cell = [topLevelObjects objectAtIndex:0]; //
}
! NSDictionary *photoData = [[self appDelegate].photoArray objectAtIndex:indexPath.row];
!
! // cell.textLabel.text = [photoData valueForKey:@"Country"];
! // cell.detailTextLabel.text = [photoData valueForKey:@"Region"];
! // cell.imageView.image = [photoData valueForKey:@"Thumbnail"];
UIImageView *imageView = (UIImageView *) [cell viewWithTag:1];
imageView.image = [photoData valueForKey:@"Thumbnail"];
UILabel *label;
label = (UILabel *) [cell viewWithTag:2];
label.text = [photoData valueForKey:@"Country"];
label = (UILabel *) [cell viewWithTag:3];
label.text = [photoData valueForKey:@"Region"];
! cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
10. • RootViewController.xib Tableview Row
height PhotoTableCell.xib height
.