从XML加载UIImage中的图像

时间:2010-02-22 09:34:29

标签: iphone uiimage

我在从XML文件加载图片时遇到问题。

//
//  BookDetailViewController.m
//  XML
//
//  Created by iPhone SDK Articles on 11/23/08.
//  Copyright 2008 www.iPhoneSDKArticles.com.
//

#import "BookDetailViewController.h"
#import "Book.h"

@implementation BookDetailViewController

@synthesize aBook;

/*
// Override initWithNibName:bundle: to load the view using a nib file then perform additional customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"Book Detail";
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [tableView reloadData];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    switch(indexPath.section)
    {
        case 0:
            cell.text = aBook.title;
            break;
        case 1:
            cell.text = aBook.author;
            break;
        case 2:
            cell.text = aBook.summary;
            break;
        case 3:
            UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com.au/logos/olympics10-icedance-hp.png"]]];

            break;

    }

    return cell;
}

- (NSString *)tableView:(UITableView *)tblView titleForHeaderInSection:(NSInteger)section {

    NSString *sectionName = nil;

    switch(section)
    {
        case 0:
            sectionName = [NSString stringWithString:@"Title"];
            break;
        case 1:
            sectionName = [NSString stringWithString:@"Author"];
            break;
        case 2:
            sectionName = [NSString stringWithString:@"Book Summary"];
            break;
    }

    return sectionName;
}

- (void)dealloc {

    [aBook release];
    [tableView release];
    [super dealloc];
}


@end

1 个答案:

答案 0 :(得分:0)

如果要在表格视图中显示图像,则必须在表格视图中实现UIImageView以显示图像。