Создание массива картинок и создание аватаров на стороне стола - PullRequest
0 голосов
/ 01 июля 2011

изучал цель C только пару дней и в настоящее время озадачен таблицами / UITableView и т. Д. Я создал таблицу, в которой перечислены 6 имен, которые я прочитал, как установить аватар (изображение для слева от текста) до 1 изображения, однако я пытался установить каждое отдельное изображение с помощью массива. Вот что я имею, никаких проблем только симулятор постоянно вылетает? Заранее спасибо.

#import <UIKit/UIKit.h>
@interface SImple_TableViewController : UIViewController 
<UITableViewDelegate, UITableViewDataSource>
{
    NSArray * listData;
    NSArray* listPics;
}

@property (nonatomic,retain) NSArray *listData;
@property (nonatomic,retain) NSArray* listPics;

@end



#import "SImple_TableViewController.h"

@implementation SImple_TableViewController

@synthesize listData, listPics;

- (void)dealloc
{
    [listData release];
    [listPics release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    NSArray *array = [[NSArray alloc] initWithObjects:@"Bradley", @"Glen",@"Alan",@"Sean",@"Mark",@"Luke",@"Jack", nil];
   NSArray *pics = [[NSArray alloc] initWithObjects:@"ME.jpg",@"Sean.jpg",@"Glenn.jpg",@"Mark.jpg",@"Luke.jpg",@"Jack.jpg",@"Alan.jpg", nil];

    self.listData = array;
   // self.listPics = pics;

    [array release];
    [pics release];
    [super viewDidLoad];
}


- (void)viewDidUnload
{
    self.listData = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

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

#pragma mark Table View Data Source Methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return [self.listData count];
    return [self.listPics count];
}

    -(UITableViewCell*)tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    { static NSString *SimpleTableIdentifier = @"SImpleTableIdentifier";


        UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc]
                     initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]autorelease];

        }



        NSUInteger row = [indexPath row];
        cell.textLabel.text = [listData objectAtIndex:row];
        return cell;


        UIImage*image = [UIImage imageNamed: listPics];
        cell.imageView.image = [listPics objectAtIndex:row];
        return cell;


}


@end

1 Ответ

2 голосов
/ 01 июля 2011

Здесь важно помнить: ни один код, который появляется после return, никогда не будет достигнут. Для примера:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return [self.listData count]; // METHOD RETURNS HERE
    return [self.listPics count]; // THIS LINE IS NEVER REACHED
}

Вы можете только return один раз.

Эта же ошибка возникает в вашем методе -(UITableViewCell*)tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath


Вот еще одна проблема, которую я вижу. Эта строка:

NSArray *pics = [[NSArray alloc] initWithObjects:@"ME.jpg",@"Sean.jpg",@"Glenn.jpg",@"Mark.jpg",@"Luke.jpg",@"Jack.jpg",@"Alan.jpg", nil];

создает массив NSString объектов. Если вы хотите поместить UIImages в массив, то вместо @"ME.jpg" вы должны иметь [UIImage imageNamed:@"ME.jpg"]. Обязательно добавьте изображение с точно таким же именем (с учетом регистра) в проект.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...