вставка NSURL или целое число в NSDictionary - PullRequest
0 голосов
/ 07 марта 2011

У меня есть класс book.h, в котором я объявил

Book.h

    NSInteger WeatherID;
    NSString *Description;  
    NSURL *PictureURL;  

BookDetailview.h

    #import <UIKit/UIKit.h>
    @class Book, XMLAppDelegate;
    @interface BookDetailViewController : UIViewController
{
    IBOutlet UITableView *tableView;
        XMLAppDelegate *appDelegate;
        Book *aBook;      //creating object of 'Book-class'
        NSMutableDictionary *EmpDictionary;
    NSMutableArray *EmpArray;
}
    @property (nonatomic, retain) Book *aBook;
    @property (nonatomic, retain) NSMutableArray *EmpArray;
    @end

BookDetailView.m

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

    NSLog(@"creation of cell");

    static NSString *CellIdentifier = @"Cell";
    ImageCell *cell = (ImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // creating cell from ImageCell.m
    NSLog(@"calling image class");
    if (cell == nil) {
        cell = [[[ImageCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; // allocating with frame
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    NSLog(@"abook ...pictutre url......%@" , aBook.PictureURL);
    EmpDictionary=[[NSMutableDictionary alloc]init];
    [EmpDictionary setValue:aBook.Description forKey:@"Description"];
    [EmpDictionary setValue:aBook.PictureURL forKey:@"PictureURL"];
    [EmpDictionary setValue:aBook.WeatherID forKey:@"WeatherID"];
    EmpArray=[[NSMutableArray alloc]init];
    [EmpArray addObject:EmpDictionary];
      NSDictionary *itemAtIndex = [self.EmpArray objectAtIndex:indexPath.row];
    [cell setData:itemAtIndex]; //call to 'setData' meyhod to ImageCell.m
    NSLog(@"set text of a cell"); 
    return cell;
}

ImageCell.m

    -(void)setData:(NSDictionary *)dic {
    self.titleLabel.text = [dic objectForKey:@"Description"];
    self.urlLabel.text = [dic objectForKey:@"PictureURL"];
    self.itemID = (NSInteger)[dic objectForKey:@"WeatherID"];
    NSLog(@"setting objects for keys");
    // setting up the imageView now
    self.imageView.image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [dic objectForKey:@"PictureURL"]]]];
    NSLog(@"setting of image");
}

Ответы [ 2 ]

1 голос
/ 07 марта 2011
[dict setValue:value forKey:key];

[dict setObject:object forKey:key];
0 голосов
/ 07 марта 2011
NSDictionary *dict1 = [[NSDictionary alloc] initWithObjectsAndKeys:
                       @"val1", @"key1", @"val2", @"key2", @"val3", @"key3",@"val4", @"key4",@"val5", @"key5",nil];
...